> Hi
>
> The ffi documentation page (http://nekovm.org/doc/ffi) describe the access of
> C functions and values from neko. What about C++ class objects, can you
> access them from neko? If yes, could someone show a little example?
There is no automatic wrapper, you'll have to bind each method by-hand.
Also, you need to store the actual instance into a field of the neko object.
Nicolas
DEFINE_KIND(k_myclass);
static value mymethod( value arg ) {
value t = val_this();
value inst;
const char *r;
val_check(arg,int);
val_check(t,object);
inst = val_field(t,"__inst");
val_check_kind(inst,k_myclass);
r = ((MyClass*)val_data(inst))->mymethod(val_int(arg));
return r?alloc_string(r):val_null;
}
static void delete_myclass( value v ) {
delete ((MyClass*)val_data(v));
}
// create class instance
static value new_myclass( /*args ? */ ) {
value i = alloc_abstract(k_myclass,new MyClass());
val_gc(i,delete_myclass);
return i;
}
DEFINE_PRIM(new_myclass,0);
DEFINE_PRIM(mymethod,1);
----------------------------------------
// from neko code :
new_myclass = $loader.loadprim("[EMAIL PROTECTED]",0);
myclass_proto = {
mymethod => $loader.loadprim("[EMAIL PROTECTED]",1);
};
// constructor
myclass = function() {
var o = $new(null);
$objsetproto(o,myclass_proto);
o.__inst = new_myclass();
return o;
}
// test
var c = myclass();
c.mymethod(0);
--
Neko : One VM to run them all
(http://nekovm.org)