Thanx for your answers Nicolas.
Very interesting things you wrote there, and I think that you answered my
questions...
Did you ever consider adding something like this natively to the language,
along with dynamic calls ?
It would Neko able to communicate with all system APIs without wrapping
them, nice thing to have for emergancy casses for Neko scripters.
Thanks again, you helped me much.
On 12/15/06, Nicolas Cannasse <[EMAIL PROTECTED]> wrote:
> 2 Nikolas, 2 Lee
>
> Thank you for your answers. However I think both you and
> Lee didn't understand what I want, or I didn't understand you :))
>
> I am totaly positive that i can create wrapper for callbacks in
> any embedable languag, be it Lua, Neko or whatever. But the problem is
> not to do it for one particular function, but as a general mechanism to
be
> used for ALL possible/eventual APIs in windows. So, your do_enum will do
> enum, but it will not do something else that require callbacks, lets
> say, enumerating fonts :)
In most dynamicly typed VM, C pointers needs to be stored into a
specific abstract VM'allocated value to prevent random crashes.
There's also a lot of problems when passing adresses of values instead
of the pointer itself.
However, as long as you don't apply any Neko operation to a C pointer,
the current implementation should be able to manipulate raw pointers
without any problem, although it's very unsafe since as long as for
example you try to print it, it will crash the VM.
To handle callbacks, you could write a set of C functions. The
neko_wrapper in previous example is quite generic but its only
assumptions are :
a) there's only 2 arguments
b) the second argument is the callback value.
Since C takes its arguments on the stack, you could as well write a very
generic wrapper :
static value *callback = NULL;
void * generic_neko_wrapper( void *a, void *b, void *c, void *d, void *e )
{
void *args[5];
args[0] = a;
args[1] = b;
args[2] = c;
args[3] = d;
args[4] = e;
return val_callN(*callback,(value*)args,5);
}
value set_callback( value f ) {
val_check_function(f,5);
if( callback == NULL )
callback = alloc_root(1);
*callback = f;
return val_null;
}
value get_generic_wrapper() {
return (value)generic_neko_wrapper;
}
This wrapper can't be called from Neko, only from C, and will directly
pass and return raw C values. But when doing this, you're losing all the
security of a VM since you will get the same crashes as in C.
Nicolas
--
Neko : One VM to run them all
(http://nekovm.org)
--
www.r-moth.com
http://r-moth.deviantart.com
--
Neko : One VM to run them all
(http://nekovm.org)