Saturday 29 April 2017

Load native C modules in duktape 2.1.0 to

I am still lost after reading the how-to article.

It is said that

The load callback is a Duktape/C function which takes the resolved module ID and: (1) returns the Ecmascript source code for the module or undefined if there's no source code, e.g. for pure C modules, (2) can populate module.exports itself, and (3) can replace module.exports.

But when loading a native C module,

  • what should be pushed into the value stack? duk_push_undefined(ctx) instead of duk_push_string(ctx, module_source)?
  • what should be returned by the load callback to its caller? return 0 instead of return 1?

I tried to call myobject_init (using the default instance in http://wiki.duktape.org/HowtoNativeConstructor.html) in the load callback cb_load_module. But duktape complains

TypeError: [object Object] not constructable

when I evaluate var MyObject = require("MyObject"), no matter if I

  • push undefined into the value stack and return 1,
  • or push nothing into the value stack and return 0.


via Sean

No comments:

Post a Comment