hi again,

Calling from c++ app into functions in embeded nekovm is solved now, whether
I get the .n from haxe or neko lang. I will write a tutorial about it.

I had some aditional things I didn't understand which I figured out, but now
I think I have just one more thing before the whole thing works.

For example. I call from c++ to the neko function cb_update() and then in
the cb_update() there are calls back to the c++ (like drawImg and loadImg).
I understood here that I have to make a custom loadprim that will return
pointers to the c++ functions so I did it like this before:

in c++
----
value neko_load( char *file ) {
    value loader;
    value args[2];
    value exc = NULL;
    value ret;
    loader = neko_default_loader(NULL,0);
    args[0] = alloc_string(file);
    args[1] = loader;

alloc_field(loader,val_id("loadprim"),alloc_function(loadprim,2,"loadprim"));
// << -- HERE
    ret =
val_callEx(loader,val_field(loader,val_id("loadmodule")),args,2,&exc);
    if( exc != NULL ) {
        buffer b = alloc_buffer(NULL);
        val_buffer(b,exc);
        printf("Uncaught exception - %s\n",val_string(buffer_to_string(b)));
        //trace(val_string(buffer_to_string(b)));
        //trace("Uncaught exception -
%s\n",val_string(buffer_to_string(b)));
        return NULL;
    }
    return ret;
}
----

I replaced the loader's loadprim with mine which was at this stage simply
this:

----
static value loadprim( value prim, value nargs )
{
    if (strcmp(val_string(prim), "loadImg") == 0)
        return alloc_function(loadImg, 1, "loadImg");
    else if (strcmp(val_string(prim), "drawImg") == 0)
        return alloc_function(drawImg,    5, "drawImg");
    else
    {
        trace("loadprim err");
        trace(val_string(prim));
        return NULL;
    }
}
----


This worked with my neko version of code which was accessing to the fucntion
like this:

----
        var load = $loader.loadprim("loadImg", 1);
----

But when I compiled with haxe there was error at loading the module. I
figured out that this is because compiling haxe to neko adds standard
libraries which also use loadprim and I replaced the default one with my
which didn't know how to load anything else than my 2 exposed functions.

I temporarily solve this by making loadprimMy so it leaft loadprim there and
I called loadprimMy in neko if I needed my functions. But I don't know if
this is the advised way... and I don't know how to call loadprimMy in haxe
(where there is Loader.local().loadPrimitive() which I suppose is wrapper
around loadprim .


alloc_field(loader,val_id("loadprimMy"),alloc_function(loadprimMy,2,"loadprimMy"));


So I am basically seeing few options here but I don't know how-to...

1) I need to write a loadprim that will be able to load my functions without
destroying the default loadprim functionality (by calling default one
somehow and if it returns null seek if I have what needs to be loaded)

2) I need to as now create my own function and change some haxe file to be
able to compile (now loadprimMy is of course undefined) - this is in a way
strange to me beacuse this function is created at runtime by c++ , but maybe
I am just complicating

something third?

Best regards and thank you so far... when I have this I think I have made a
full circle and I can start developing with haxe + ptk

Janko Metelko
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to