Hello all,
While doing some bindings/scripting for some libraries I'm doing I've
found some issue that I'm not sure exactly how to solve. Basically the
library I'm trying to do the bindings for has some kind of property
system and as such I'm able to do some introspection on the library
objects to know what properties it has and of what type (int, string,
whatever). What I'm trying to do with neko is to be able to add
fields/functions for such properties at runtime, given that neko does
not have the setter/getter concept for fields I have to use functions
to set/get such properties, isnt a big issue, but given that the
functions must be created at runtime i just need to create a single
function on C, define a new function with neko (alloc_function) and
pass some data that tells me what kind of value i need to set on the
library object. Some pseudocode of a generic object "obj" and some
properties defined by the "property" type
value object_initialize(value intptr)
{
val_check_kind(intptr, k_object);
obj o = val_data(value);
/* introspect the object */
foreach (property p in o.properties)
{
value gen_setter;
value ret;
gen_setter = alloc_function(value_setter, 1, p.name);
alloc_field(ret, val_id(p.name), gen_setter);
}
}
value value_setter(value v)
{
value thiz = val_this();
obj o = val_data(thiz);
/* at this point we have the object to set the value and the value itself */
/* but how to differentiate between the calls? i.e how to know what is the
* property name to set the value to? p.name in the above function?
is there a way?
}
Is it possible to handle this with neko? does it support this kind of
dynamic function creation?
Regards
--
Neko : One VM to run them all
(http://nekovm.org)