diff --git a/bin/nodejs/Makefile.am b/bin/nodejs/Makefile.am index 5a25a20e2081d560cae68c64f541b0aa5ef6f0d0..ffd5e9c7bde935a344f40e4eee083668875f1f7d 100644 --- a/bin/nodejs/Makefile.am +++ b/bin/nodejs/Makefile.am @@ -3,11 +3,11 @@ include $(top_srcdir)/globals.mk BUILT_SOURCES= \ ring_wrapper.cpp \ build/Makefile \ + build/Release/dring.node \ build/Release/obj.target/dring.node ring_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.i $(SWIG) -v -c++ -javascript -node -o ring_wrapper.cpp nodejs_interface.i - sed -i 's/_wrap_init)/init)/g' ring_wrapper.cpp build/Makefile: ring_wrapper.cpp binding.gyp node-gyp configure diff --git a/bin/nodejs/callback.h b/bin/nodejs/callback.h index 30ef45f3f12c73bbd5c2cfa4a58f1cd36a0d13a4..eb564e79d78eb3c5b14a6ae36ebb5a4d0fff07e9 100755 --- a/bin/nodejs/callback.h +++ b/bin/nodejs/callback.h @@ -59,13 +59,13 @@ void setCallback(const std::string& signal, Local<Function>& func){ } } -void parseCbMap(const Local<Value>& arg){ - Local<Object> array = arg->ToObject(); - Local<Array> props = array->GetOwnPropertyNames(); +void parseCbMap(const Local<Value>& callbackMap){ + Local<Object> cbAssocArray = callbackMap->ToObject(); + Local<Array> props = cbAssocArray->GetOwnPropertyNames(); for (uint32_t i = 0; i < props->Length(); ++i) { const Local<Value> key_local = props->Get(i); std::string key = *String::Utf8Value(key_local); - Handle<Object> buffer = array->Get(V8_STRING_NEW(key))->ToObject(); + Handle<Object> buffer = cbAssocArray->Get(V8_STRING_NEW(key))->ToObject(); Local<Function> func = Local<Function>::Cast(buffer); setCallback(key,func); } diff --git a/bin/nodejs/nodejs_interface.i b/bin/nodejs/nodejs_interface.i index fee585617782373853b55d62d9a867b6d70ad7a0..da94ac4911f02c8216a5a2e08d5c1c8db0f93e55 100644 --- a/bin/nodejs/nodejs_interface.i +++ b/bin/nodejs/nodejs_interface.i @@ -106,13 +106,24 @@ namespace std { #include "callback.h" %} +//typemap for passing Callbacks +%typemap(in) v8::Local<v8::Function> { + $1 = v8::Local<v8::Function>::Cast($input); +} + +//typemap for handling map of functions +%typemap(in) const v8::Handle<v8::Value> { + $1 = $input; +} + + %inline %{ /* some functions that need to be declared in *_wrap.cpp * that are not declared elsewhere in the c++ code */ -void init(const SwigV8Arguments& args){ - parseCbMap(args[0]); +void init(const v8::Handle<v8::Value> &funcMap){ + parseCbMap(funcMap); using namespace std::placeholders; using std::bind; @@ -143,8 +154,6 @@ void init(const SwigV8Arguments& args){ DRing::start(); } - - %} #ifndef SWIG /* some bad declarations */