diff --git a/Examples/javascript/native/example.i b/Examples/javascript/native/example.i index 212765fa4..740238413 100644 --- a/Examples/javascript/native/example.i +++ b/Examples/javascript/native/example.i @@ -1,7 +1,13 @@ /* File : example.i */ %module example +// placeholder() used to help SWIG generate "SWIG_From_int" call +%{ + int placeholder(); +%} +int placeholder() { return 0; } +// actual demo code %wrapper %{ #ifdef SWIG_V8_VERSION /* Engine: Node || V8 */ @@ -38,4 +44,4 @@ %} -%native(num_to_string) void JavaScript_exampleV8_callback_function(); +%native(magicNumber) void JavaScript_do_work(); diff --git a/Examples/javascript/native/runme.js b/Examples/javascript/native/runme.js index 6577bb1fb..8ea0a8bcc 100644 --- a/Examples/javascript/native/runme.js +++ b/Examples/javascript/native/runme.js @@ -1,5 +1,3 @@ var example = require("example"); -function callback(msg) { console.log(msg); } - -example.num_to_string(callback); +console.info("My magic number is: ", example.magicNumber()); diff --git a/Examples/test-suite/native_directive.i b/Examples/test-suite/native_directive.i index f2699c421..9ae76e0b7 100644 --- a/Examples/test-suite/native_directive.i +++ b/Examples/test-suite/native_directive.i @@ -42,6 +42,9 @@ extern "C" JNIEXPORT jint JNICALL Java_native_1directive_native_1directiveJNI_Co #endif +// TODO: C# +// TODO: Python + #ifdef SWIGJAVASCRIPT %native(CountAlphaCharacters) void JavaScript_alpha_count(); diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index e36f31308..68c97e641 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -787,13 +787,18 @@ int JSEmitter::emitWrapperFunction(Node *n) { } int JSEmitter::emitNativeFunction(Node *n) { - String *wrap_name = Getattr(n, "wrap:name"); - - Setattr(n, "feature:extend", "last"); + String *wrapname = Getattr(n, "wrap:name"); + // ismember never seems to be the case; + // it is technically possible to add native member functions, + // just not at the moment? leaving this as an option for later; + // the code will automatically defaulting to static space + if (GetFlag(n, "ismember") != 0) + Setattr(n, "feature:extend", "1"); // member space + else + Setattr(n, "feature:extend", "0"); // static space enterFunction(n); - state.function(WRAPPER_NAME, wrap_name); + state.function(WRAPPER_NAME, wrapname); exitFunction(n); - return SWIG_OK; }