[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: calling define-class function from C++ source file
From: |
Andreas Rottmann |
Subject: |
Re: calling define-class function from C++ source file |
Date: |
Fri, 17 Oct 2003 14:12:46 +0200 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) |
Laurent Marzullo <address@hidden> writes:
> Hello,
>
> Could anyone give me an example of how to call the function
> define-class from C++ once the goop module has been loaded.
>
> // C++
> scm_load_goops();
> scm_apply( ??????? );
>
> In fact I would like to write in C++ the following statment
> (define-class <MyClass> ()
> (r #:init-value 0))
>
> Could someone show me how to write this Scheme statment from
> C/C++ ???
>
As I already told you, my Yehia code does this. From
http://cvs.sourceforge.net/viewcvs.py/ucxx/yehia/plugins/guile/guile-script.cc?rev=1.3&view=auto:
---------------------------
Object& guileObjectFactory::create_class(const Signature& supers)
{
Signature::const_iterator it;
int i;
SCM ssupers = SCM_EOL;
for (i = supers.size() - 1, it = supers.end(); i >= 0; i--)
ssupers = scm_cons(dynamic_cast<guileObject *>(find_class(**--it))->sobj(),
ssupers);
if (supers.size() == 0)
ssupers = scm_cons(scm_class_object, ssupers);
// We need to create a new metaclass for the class, so we can
// implement static methods
#if 0 // this seems to cause infinite loops in goops
SCM ensure_meta = SCM_VARIABLE_REF(scm_c_module_lookup(scm_module_goops,
"ensure-metaclass"));
SCM meta = scm_apply(ensure_meta, scm_list_2(ssupers, SCM_BOOL_F),
SCM_EOL);
#else
SCM meta = scm_class_class;
#endif
meta = scm_basic_make_class(scm_class_class,
scm_str2symbol("yehia:meta:<unknown>"),
scm_list_1(meta), SCM_EOL);
SCM slots = scm_list_1(scm_list_3(scm_str2symbol("%yehia-instance"),
scm_c_make_keyword("init-value"),
SCM_BOOL_F));
SCM sclass = scm_basic_make_class(meta, scm_str2symbol("<unknown>"),
ssupers, slots);
return create_object(sclass);
}
-----------------------------
Regards, Andy
--
Andreas Rottmann | address@hidden | address@hidden | address@hidden
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
This reality is really just a fucked-up dream -- Papa Roach