Aha , it helps a lot.. I don't have the whole picture yet but I know
understand a lot more now..

I have made it like this now (It still doesn't work fully)
C++ >>>

//I would like to call this
value get123() {
    return alloc_int(123);
}

//I do this because it seeems you did it too at
DECLARE_PRIM(get123,0)

//I always return one function to make the test minimal
static value loadprim( value prim, value nargs ) {
    return alloc_function(get123, 0, "get123");
}

//this one should override the loadprim with new one
//do those argv, argc have any meaning?
//maybe I shouldn't just call these functions but I should
//owerwrite something and let neko inicialisation procedure
//call them on it's own?
value neko_set_loader() {
    value l = neko_default_loader(NULL , 0);
    alloc_field(l,val_id("loadprim"),alloc_function(loadprim,2,"loadprim"));
    return l;
}

main {
    ....
    //prepare the neko
    neko_vm *vm;
    value module;
    neko_global_init(NULL);
    vm = neko_vm_alloc(NULL);
    neko_vm_select(vm);

    //here I set loader..
    neko_set_loader();

    module = n_load("mymodule.n");

    if( module == NULL ) {
         printf("Failed to load module !\n"); return -1;
    }
    n_execute(module);
    ....
}
<<<

If I have this script (without loadprim(...)) then it the exe works

NEKO >>>
//var p = $loader.loadprim("get123", 0);

$exports.x = 33;

$exports.f = function(x) { return x + 1; }

$exports.getx = function(x) {
    return x + 1;
}
<<<

If I have this enable loadprim here then I get ""Failed to load module !""
when I try to load it and app exits

NEKO >>>
var p = $loader.loadprim("get123", 0);

$exports.x = 33;

$exports.f = function(x) { return x + 1; }

$exports.getx = function(x) {
    return x + 1;
}
<<<

If I have this enable loadprim here then the app loads the module but when I
call getx function from C it exits (and throws some unhandeled exception in
MSVCRT.dll ..)

NEKO >>>

$exports.x = 33;

$exports.f = function(x) { return x + 1; }

$exports.getx = function(x) {
    var p = $loader.loadprim("get123", 0);
    return x + 1;
}
<<<

Can you maybe see what I am doing wrong?
best regards,
Janko
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to