duktape
duktape copied to clipboard
how to access main module when using duk_module_node_peval_main(...)
I managed to implement the Node.js behavior while using require based on module-node and it's working so far with my modules.
But how do I access a variable or call a function of the "main" module from c++? I exported a variable in the main module, but I can't access the variable via duk_get_global_string or duk_get_prop_string .
I looked in to the source and was able to get the object index of the hidden variable mainModule and from there to access the exports object. But is this the only way?
duk_push_global_stash(ctx);
duk_get_prop_string(ctx, -1, "\xff" "mainModule");
duk_get_prop_string(ctx, -1, "exports");