diff --git a/binding.gyp b/binding.gyp index e56bcee..9647904 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,10 +14,11 @@ { 'target_name': 'glfw', 'defines': [ - 'VERSION=0.3.1', + 'VERSION=0.4.0', ], 'sources': [ - 'src/atb.cc', 'src/glfw.cc' + 'src/atb.cc', + 'src/glfw.cc' ], 'include_dirs': [ "", @@ -33,12 +33,12 @@ "test": "test" }, "engines": { - "node": "0.6.5-0.11.10" + "node": ">=0.6.5 <4.0.0" }, "scripts": { "install": "node-gyp rebuild" }, "dependencies": { - "nan": "^1.2.0" + "nan": "^2.0.9" } } diff --git a/src/atb.cc b/src/atb.cc index de06173..35d7979 100644 --- a/src/atb.cc +++ b/src/atb.cc @@ -5,29 +5,30 @@ using namespace std; namespace atb { -Persistent AntTweakBar::constructor_template; +Nan::Persistent AntTweakBar::constructor_template; #define DEFINE_ATB_CONSTANT(constant) \ NODE_DEFINE_CONSTANT_VALUE(ctor->InstanceTemplate(), "TYPE_" #constant, TW_TYPE_##constant); -void AntTweakBar::Initialize (Handle target) { - NanScope(); +NAN_MODULE_INIT(AntTweakBar::Initialize) +{ + Nan::HandleScope scope; - Local ctor = FunctionTemplate::New(AntTweakBar::New); + Local ctor = Nan::New(AntTweakBar::New); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(JS_STR("AntTweakBar")); - NODE_SET_PROTOTYPE_METHOD(ctor, "Init", Init); - NODE_SET_PROTOTYPE_METHOD(ctor, "Terminate", Terminate); - NODE_SET_PROTOTYPE_METHOD(ctor, "WindowSize", WindowSize); - NODE_SET_PROTOTYPE_METHOD(ctor, "Draw", Draw); - NODE_SET_PROTOTYPE_METHOD(ctor, "NewBar", NewBar); - NODE_SET_PROTOTYPE_METHOD(ctor, "Define", Define); - NODE_SET_PROTOTYPE_METHOD(ctor, "DefineEnum", DefineEnum); + Nan::SetPrototypeMethod(ctor, "Init", Init); + Nan::SetPrototypeMethod(ctor, "Terminate", Terminate); + Nan::SetPrototypeMethod(ctor, "WindowSize", WindowSize); + Nan::SetPrototypeMethod(ctor, "Draw", Draw); + Nan::SetPrototypeMethod(ctor, "NewBar", NewBar); + Nan::SetPrototypeMethod(ctor, "Define", Define); + Nan::SetPrototypeMethod(ctor, "DefineEnum", DefineEnum); #define NODE_DEFINE_CONSTANT_VALUE(target, name, value) \ (target)->Set(JS_STR(name), \ - NanNew(value), \ + Nan::New(value), \ static_cast(v8::ReadOnly|v8::DontDelete)) DEFINE_ATB_CONSTANT(CHAR); @@ -50,18 +51,18 @@ void AntTweakBar::Initialize (Handle target) { //DEFINE_ATB_CONSTANT(CDSTRING); - NanAssignPersistent(constructor_template, ctor->GetFunction()); - target->Set(JS_STR("AntTweakBar"), ctor->GetFunction()); + constructor_template.Reset(ctor->GetFunction()); + Nan::Set(target, JS_STR("AntTweakBar"), ctor->GetFunction()); } NAN_METHOD(AntTweakBar::New) { - if (!args.IsConstructCall()) - return NanThrowTypeError("Constructor cannot be called as a function."); + if (!info.IsConstructCall()) + return Nan::ThrowTypeError("Constructor cannot be called as a function."); - NanScope(); - AntTweakBar *cl = new AntTweakBar(args.This()); - cl->Wrap(args.This()); - NanReturnValue(args.This()); + Nan::HandleScope scope; + AntTweakBar *cl = new AntTweakBar(info.This()); + cl->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } AntTweakBar::AntTweakBar(Handle wrapper) @@ -73,27 +74,27 @@ AntTweakBar::~AntTweakBar () { } NAN_METHOD(AntTweakBar::Init) { - NanScope(); + Nan::HandleScope scope; TwInit(TW_OPENGL, NULL); - NanReturnUndefined(); + return; } NAN_METHOD(AntTweakBar::Terminate) { - NanScope(); + Nan::HandleScope scope; TwTerminate(); - NanReturnUndefined(); + return; } NAN_METHOD(AntTweakBar::WindowSize) { - NanScope(); - unsigned int w=args[0]->Uint32Value(); - unsigned int h=args[1]->Uint32Value(); + Nan::HandleScope scope; + unsigned int w=info[0]->Uint32Value(); + unsigned int h=info[1]->Uint32Value(); TwWindowSize(w,h); - NanReturnUndefined(); + return; } NAN_METHOD(AntTweakBar::Draw) { - NanScope(); + Nan::HandleScope scope; // save state GLint program;//, ab, eab; @@ -106,29 +107,29 @@ NAN_METHOD(AntTweakBar::Draw) { // restore state glUseProgram(program); - NanReturnUndefined(); + return; } NAN_METHOD(AntTweakBar::Define) { - NanScope(); + Nan::HandleScope scope; - String::AsciiValue str(args[0]); + String::Utf8Value str(info[0]); TwDefine(*str); - NanReturnUndefined(); + return; } NAN_METHOD(AntTweakBar::DefineEnum) { - NanScope(); + Nan::HandleScope scope; - String::AsciiValue str(args[0]); - Local arr=Local::Cast(args[1]); - int num=args[2]->IsUndefined() ? arr->Length() : args[2]->Uint32Value(); + String::Utf8Value str(info[0]); + Local arr=Local::Cast(info[1]); + int num=info[2]->IsUndefined() ? arr->Length() : info[2]->Uint32Value(); TwEnumVal *vals=new TwEnumVal[num]; for(int i=0;iGet(i)->ToString()); + String::Utf8Value str(arr->Get(i)->ToString()); vals[i].Label=strdup(*str); //cout<<" Adding value: "<handle()); } -Persistent Bar::constructor_template; +Nan::Persistent Bar::constructor_template; -void Bar::Initialize (Handle target) { - NanScope(); +NAN_MODULE_INIT(Bar::Initialize) +{ + Nan::HandleScope scope; - Local ctor = FunctionTemplate::New(Bar::New); + Local ctor = Nan::New(Bar::New); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(JS_STR("Bar")); - NODE_SET_PROTOTYPE_METHOD(ctor, "AddVar", AddVar); - NODE_SET_PROTOTYPE_METHOD(ctor, "RemoveVar", RemoveVar); - NODE_SET_PROTOTYPE_METHOD(ctor, "RemoveAllVars", RemoveAllVars); - NODE_SET_PROTOTYPE_METHOD(ctor, "AddButton", AddButton); - NODE_SET_PROTOTYPE_METHOD(ctor, "AddSeparator", AddSeparator); + Nan::SetPrototypeMethod(ctor, "AddVar", AddVar); + Nan::SetPrototypeMethod(ctor, "RemoveVar", RemoveVar); + Nan::SetPrototypeMethod(ctor, "RemoveAllVars", RemoveAllVars); + Nan::SetPrototypeMethod(ctor, "AddButton", AddButton); + Nan::SetPrototypeMethod(ctor, "AddSeparator", AddSeparator); - NanAssignPersistent(constructor_template, ctor->GetFunction()); - target->Set(JS_STR("Bar"), ctor->GetFunction()); + constructor_template.Reset(ctor->GetFunction()); + Nan::Set(target, JS_STR("Bar"), ctor->GetFunction()); } NAN_METHOD(Bar::New) { - if (!args.IsConstructCall()) - return NanThrowTypeError("Constructor cannot be called as a function."); + if (!info.IsConstructCall()) + return Nan::ThrowTypeError("Constructor cannot be called as a function."); - NanScope(); - Bar *cl = new Bar(args.This()); - cl->Wrap(args.This()); - NanReturnValue(args.This()); + Nan::HandleScope scope; + Bar *cl = new Bar(info.This()); + cl->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } Bar::Bar(Handle wrapper) : bar(NULL) @@ -197,12 +199,12 @@ Bar::~Bar () { Bar *Bar::New(TwBar *zbar) { - NanScope(); + Nan::HandleScope scope; - Local cons = NanNew(constructor_template); + Local cons = Nan::New(constructor_template); Local obj = cons->NewInstance(); - Bar *v8bar = ObjectWrap::Unwrap(obj); + Bar *v8bar = Nan::ObjectWrap::Unwrap(obj); v8bar->bar = zbar; return v8bar; @@ -211,11 +213,11 @@ Bar *Bar::New(TwBar *zbar) void TW_CALL SetCallback(const void *value, void *clientData) { // cout<<"in SetCallback"<(clientData); // cout<<" cb type: "<type< argv[1]; + Local argv[1]; switch(cb->type) { case TW_TYPE_INT8: @@ -244,7 +246,7 @@ void TW_CALL SetCallback(const void *value, void *clientData) { break; case TW_TYPE_DIR3F: { const float *val=static_cast(value); - Local arr=Array::New(3); + Local arr=Nan::New(3); arr->Set(0,JS_NUM(val[0])); arr->Set(1,JS_NUM(val[1])); arr->Set(2,JS_NUM(val[2])); @@ -259,8 +261,8 @@ void TW_CALL SetCallback(const void *value, void *clientData) { TryCatch try_catch; - Local constructorHandle = NanNew(cb->setter); - constructorHandle->Call(Context::GetCurrent()->Global(), 1, argv); + Local constructorHandle = Nan::New(cb->setter); + constructorHandle->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv); if (try_catch.HasCaught()) FatalException(try_catch); @@ -270,12 +272,12 @@ void TW_CALL SetCallback(const void *value, void *clientData) { void TW_CALL GetCallback(void *value, void *clientData) { // cout<<"in GetCallback"<(clientData); // build callback values - Handle argv[1]; - argv[0]=Undefined(); + Local argv[1]; + argv[0]=Nan::Undefined(); TryCatch try_catch; @@ -283,13 +285,13 @@ void TW_CALL GetCallback(void *value, void *clientData) { // Local ctx=Context::GetCurrent(); // Local global=ctx->Global(); // cout<<"global context: "<<*ctx<<" global object: "<<*global< fct=NanNew(cb->getter); + Local fct=Nan::New(cb->getter); // Handle name=fct->GetName(); - // String::AsciiValue str(name); + // String::Utf8Value str(name); // cout<<"getter name: "<<*str<<" callable? "<IsCallable()<<" function? "<IsFunction()<Has(name->ToString())< val=fct->Call(Context::GetCurrent()->Global(), 1, argv); + Local val=fct->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv); if (try_catch.HasCaught()) FatalException(try_catch); @@ -383,17 +385,17 @@ void TW_CALL GetCallback(void *value, void *clientData) { void TW_CALL SetButtonCallback(void *clientData) { //cout<<"in SetButtonCallback"<(clientData); //cout<<" cb type: "<type< argv[1]; - argv[0]=Undefined(); + Local argv[1]; + argv[0]=Nan::Undefined(); TryCatch try_catch; - Local constructorHandle = NanNew(cb->setter); - constructorHandle->Call(Context::GetCurrent()->Global(), 1, argv); + Local constructorHandle = Nan::New(cb->setter); + constructorHandle->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv); if (try_catch.HasCaught()) FatalException(try_catch); @@ -401,11 +403,11 @@ void TW_CALL SetButtonCallback(void *clientData) { } NAN_METHOD(Bar::AddVar) { - NanScope(); - Bar *bar = ObjectWrap::Unwrap(args.This()); - String::AsciiValue name(args[0]); - uint32_t type=args[1]->Uint32Value(); - Local params=Local::Cast(args[2]); + Nan::HandleScope scope; + Bar *bar = Nan::ObjectWrap::Unwrap(info.This()); + String::Utf8Value name(info[0]); + uint32_t type=info[1]->Uint32Value(); + Local params=Local::Cast(info[2]); Local getter=Local::Cast(params->Get(JS_STR("getter"))); Local setter=Local::Cast(params->Get(JS_STR("setter"))); CB *callbacks=new CB(); @@ -413,15 +415,15 @@ NAN_METHOD(Bar::AddVar) { callbacks->name=strdup(*name); callbacks->type=type; if(!getter->IsUndefined()) { - NanAssignPersistent(callbacks->getter, getter); + callbacks->getter.Reset( getter); // cout<<"[AddVarRW] adding getter "<IsUndefined()) { - NanAssignPersistent(callbacks->setter, setter); + callbacks->setter.Reset( setter); // cout<<"[AddVarRW] adding setter "<IsString()) \ - NanThrowTypeError("Argument " #I " must be a string"); \ - String::Utf8Value VAR(args[I]->ToString()); + if (info.Length() <= (I) || !info[I]->IsString()) \ + Nan::ThrowTypeError("Argument " #I " must be a string"); \ + String::Utf8Value VAR(info[I]->ToString()); #define REQ_EXT_ARG(I, VAR) \ - if (args.Length() <= (I) || !args[I]->IsExternal()) \ - NanThrowTypeError("Argument " #I " invalid"); \ - Local VAR = Local::Cast(args[I]); + if (info.Length() <= (I) || !info[I]->IsExternal()) \ + Nan::ThrowTypeError("Argument " #I " invalid"); \ + Local VAR = Local::Cast(info[I]); #define REQ_FUN_ARG(I, VAR) \ - if (args.Length() <= (I) || !args[I]->IsFunction()) \ - NanThrowTypeError("Argument " #I " must be a function"); \ - Local VAR = Local::Cast(args[I]); + if (info.Length() <= (I) || !info[I]->IsFunction()) \ + Nan::ThrowTypeError("Argument " #I " must be a function"); \ + Local VAR = Local::Cast(info[I]); -#define REQ_ERROR_THROW(error) if (ret == error) NanThrowError(String::New(#error)); +#define REQ_ERROR_THROW(error) if (ret == error) Nan::ThrowError(String::New(#error)); } #endif /* COMMON_H_ */ diff --git a/src/glfw.cc b/src/glfw.cc index 3b5c6b0..3c8bee7 100644 --- a/src/glfw.cc +++ b/src/glfw.cc @@ -18,45 +18,45 @@ namespace glfw { /* @Module: GLFW initialization, termination and version querying */ NAN_METHOD(Init) { - NanScope(); - NanReturnValue(JS_BOOL(glfwInit()==1)); + Nan::HandleScope scope; + info.GetReturnValue().Set(JS_BOOL(glfwInit()==1)); } NAN_METHOD(Terminate) { - NanScope(); + Nan::HandleScope scope; glfwTerminate(); - NanReturnUndefined(); + return; } NAN_METHOD(GetVersion) { - NanScope(); + Nan::HandleScope scope; int major, minor, rev; glfwGetVersion(&major,&minor,&rev); - Local arr=Array::New(3); + Local arr=Nan::New(3); arr->Set(JS_STR("major"),JS_INT(major)); arr->Set(JS_STR("minor"),JS_INT(minor)); arr->Set(JS_STR("rev"),JS_INT(rev)); - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } NAN_METHOD(GetVersionString) { - NanScope(); + Nan::HandleScope scope; const char* ver=glfwGetVersionString(); - NanReturnValue(JS_STR(ver)); + info.GetReturnValue().Set(JS_STR(ver)); } /* @Module: Time input */ NAN_METHOD(GetTime) { - NanScope(); - NanReturnValue(JS_NUM(glfwGetTime())); + Nan::HandleScope scope; + info.GetReturnValue().Set(JS_NUM(glfwGetTime())); } NAN_METHOD(SetTime) { - NanScope(); - double time = args[0]->NumberValue(); + Nan::HandleScope scope; + double time = info[0]->NumberValue(); glfwSetTime(time); - NanReturnUndefined(); + return; } /* @Module: monitor handling */ @@ -64,18 +64,18 @@ NAN_METHOD(SetTime) { /* TODO: Monitor configuration change callback */ NAN_METHOD(GetMonitors) { - NanScope(); + Nan::HandleScope scope; int monitor_count, mode_count, xpos, ypos, width, height; int i, j; GLFWmonitor **monitors = glfwGetMonitors(&monitor_count); GLFWmonitor *primary = glfwGetPrimaryMonitor(); const GLFWvidmode *mode, *modes; - Local js_monitors = Array::New(monitor_count); + Local js_monitors = Nan::New(monitor_count); Local js_monitor, js_mode; Local js_modes; for(i=0; i(); js_monitor->Set(JS_STR("is_primary"), JS_BOOL(monitors[i] == primary)); js_monitor->Set(JS_STR("index"), JS_INT(i)); @@ -95,9 +95,9 @@ NAN_METHOD(GetMonitors) { js_monitor->Set(JS_STR("rate"), JS_INT(mode->refreshRate)); modes = glfwGetVideoModes(monitors[i], &mode_count); - js_modes = Array::New(mode_count); + js_modes = Nan::New(mode_count); for(j=0; j(); js_mode->Set(JS_STR("width"), JS_INT(modes[j].width)); js_mode->Set(JS_STR("height"), JS_INT(modes[j].height)); js_mode->Set(JS_STR("rate"), JS_INT(modes[j].refreshRate)); @@ -109,37 +109,39 @@ NAN_METHOD(GetMonitors) { js_monitors->Set(JS_INT(i), js_monitor); } - NanReturnValue(js_monitors); + info.GetReturnValue().Set(js_monitors); } /* @Module: Window handling */ -Persistent glfw_events; +Nan::Persistent glfw_events; int lastX=0,lastY=0; bool windowCreated=false; -void NAN_INLINE(CallEmitter(int argc, Handle argv[])) { - NanScope(); +void NAN_INLINE(CallEmitter(int argc, Local argv[])) { + Nan::HandleScope scope; // MakeCallback(glfw_events, "emit", argc, argv); - if(NanNew(glfw_events)->Has(JS_STR("emit"))) { - Local callback = NanNew(glfw_events)->Get(JS_STR("emit")).As(); + if(Nan::New(glfw_events)->Has(JS_STR("emit"))) { + // Local callback = Nan::New(glfw_events)->Get(JS_STR("emit")).As(); + Nan::Callback callback(Nan::New(glfw_events)->Get(JS_STR("emit")).As()); if (!callback.IsEmpty()) { - callback->Call(Context::GetCurrent()->Global(),argc,argv); + // callback->Call(Context::GetCurrent()->Global(),argc,argv); + callback.Call(argc,argv); } } } /* Window callbacks handling */ void APIENTRY windowPosCB(GLFWwindow *window, int xpos, int ypos) { - NanScope(); + Nan::HandleScope scope; //cout<<"resizeCB: "< evt=Array::New(3); + Local evt=Nan::New(3); evt->Set(JS_STR("type"),JS_STR("window_pos")); evt->Set(JS_STR("xpos"),JS_INT(xpos)); evt->Set(JS_STR("ypos"),JS_INT(ypos)); - Handle argv[2] = { + Local argv[2] = { JS_STR("window_pos"), // event name evt }; @@ -148,15 +150,15 @@ void APIENTRY windowPosCB(GLFWwindow *window, int xpos, int ypos) { } void APIENTRY windowSizeCB(GLFWwindow *window, int w, int h) { - NanScope(); + Nan::HandleScope scope; //cout<<"resizeCB: "< evt=Array::New(3); + Local evt=Nan::New(3); evt->Set(JS_STR("type"),JS_STR("resize")); evt->Set(JS_STR("width"),JS_INT(w)); evt->Set(JS_STR("height"),JS_INT(h)); - Handle argv[2] = { + Local argv[2] = { JS_STR("resize"), // event name evt }; @@ -165,15 +167,15 @@ void APIENTRY windowSizeCB(GLFWwindow *window, int w, int h) { } void APIENTRY windowFramebufferSizeCB(GLFWwindow *window, int w, int h) { - NanScope(); + Nan::HandleScope scope; //cout<<"resizeCB: "< evt=Array::New(3); + Local evt=Nan::New(3); evt->Set(JS_STR("type"),JS_STR("framebuffer_resize")); evt->Set(JS_STR("width"),JS_INT(w)); evt->Set(JS_STR("height"),JS_INT(h)); - Handle argv[2] = { + Local argv[2] = { JS_STR("framebuffer_resize"), // event name evt }; @@ -182,9 +184,9 @@ void APIENTRY windowFramebufferSizeCB(GLFWwindow *window, int w, int h) { } void APIENTRY windowCloseCB(GLFWwindow *window) { - NanScope(); + Nan::HandleScope scope; - Handle argv[1] = { + Local argv[1] = { JS_STR("quit"), // event name }; @@ -192,13 +194,13 @@ void APIENTRY windowCloseCB(GLFWwindow *window) { } void APIENTRY windowRefreshCB(GLFWwindow *window) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(2); + Local evt=Nan::New(2); evt->Set(JS_STR("type"),JS_STR("refresh")); evt->Set(JS_STR("window"),JS_NUM((uint64_t) window)); - Handle argv[2] = { + Local argv[2] = { JS_STR("refresh"), // event name evt }; @@ -207,13 +209,13 @@ void APIENTRY windowRefreshCB(GLFWwindow *window) { } void APIENTRY windowIconifyCB(GLFWwindow *window, int iconified) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(2); + Local evt=Nan::New(2); evt->Set(JS_STR("type"),JS_STR("iconified")); evt->Set(JS_STR("iconified"),JS_BOOL(iconified)); - Handle argv[2] = { + Local argv[2] = { JS_STR("iconified"), // event name evt }; @@ -222,13 +224,13 @@ void APIENTRY windowIconifyCB(GLFWwindow *window, int iconified) { } void APIENTRY windowFocusCB(GLFWwindow *window, int focused) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(2); + Local evt=Nan::New(2); evt->Set(JS_STR("type"),JS_STR("focused")); evt->Set(JS_STR("focused"),JS_BOOL(focused)); - Handle argv[2] = { + Local argv[2] = { JS_STR("focused"), // event name evt }; @@ -313,9 +315,9 @@ void APIENTRY keyCB(GLFWwindow *window, int key, int scancode, int action, int m const char *actionNames = "keyup\0 keydown\0keypress"; if(!TwEventKeyGLFW(key,action)) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(7); + Local evt=Nan::New(7); evt->Set(JS_STR("type"), JS_STR( &actionNames[action << 3] )); evt->Set(JS_STR("ctrlKey"),JS_BOOL(mods & GLFW_MOD_CONTROL)); evt->Set(JS_STR("shiftKey"),JS_BOOL(mods & GLFW_MOD_SHIFT)); @@ -342,7 +344,7 @@ void APIENTRY keyCB(GLFWwindow *window, int key, int scancode, int action, int m evt->Set(JS_STR("keyCode"),JS_INT(key)); evt->Set(JS_STR("charCode"),JS_INT(charCode)); - Handle argv[2] = { + Local argv[2] = { JS_STR(&actionNames[action << 3]), // event name evt }; @@ -361,16 +363,16 @@ void APIENTRY cursorPosCB(GLFWwindow* window, double x, double y) { lastX=x; lastY=y; - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(5); + Local evt=Nan::New(5); evt->Set(JS_STR("type"),JS_STR("mousemove")); - evt->Set(JS_STR("pageX"),JS_INT(x)); - evt->Set(JS_STR("pageY"),JS_INT(y)); - evt->Set(JS_STR("x"),JS_INT(x)); - evt->Set(JS_STR("y"),JS_INT(y)); + evt->Set(JS_STR("pageX"),JS_NUM(x)); + evt->Set(JS_STR("pageY"),JS_NUM(y)); + evt->Set(JS_STR("x"),JS_NUM(x)); + evt->Set(JS_STR("y"),JS_NUM(y)); - Handle argv[2] = { + Local argv[2] = { JS_STR("mousemove"), // event name evt }; @@ -380,13 +382,13 @@ void APIENTRY cursorPosCB(GLFWwindow* window, double x, double y) { } void APIENTRY cursorEnterCB(GLFWwindow* window, int entered) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(2); + Local evt=Nan::New(2); evt->Set(JS_STR("type"),JS_STR("mouseenter")); evt->Set(JS_STR("entered"),JS_INT(entered)); - Handle argv[2] = { + Local argv[2] = { JS_STR("mouseenter"), // event name evt }; @@ -396,8 +398,8 @@ void APIENTRY cursorEnterCB(GLFWwindow* window, int entered) { void APIENTRY mouseButtonCB(GLFWwindow *window, int button, int action, int mods) { if(!TwEventMouseButtonGLFW(button,action)) { - NanScope(); - Local evt=Array::New(7); + Nan::HandleScope scope; + Local evt=Nan::New(7); evt->Set(JS_STR("type"),JS_STR(action ? "mousedown" : "mouseup")); evt->Set(JS_STR("button"),JS_INT(button)); evt->Set(JS_STR("which"),JS_INT(button)); @@ -406,7 +408,7 @@ void APIENTRY mouseButtonCB(GLFWwindow *window, int button, int action, int mods evt->Set(JS_STR("pageX"),JS_INT(lastX)); evt->Set(JS_STR("pageY"),JS_INT(lastY)); - Handle argv[2] = { + Local argv[2] = { JS_STR(action ? "mousedown" : "mouseup"), // event name evt }; @@ -417,15 +419,15 @@ void APIENTRY mouseButtonCB(GLFWwindow *window, int button, int action, int mods void APIENTRY scrollCB(GLFWwindow *window, double xoffset, double yoffset) { if(!TwEventMouseWheelGLFW(yoffset)) { - NanScope(); + Nan::HandleScope scope; - Local evt=Array::New(3); + Local evt=Nan::New(3); evt->Set(JS_STR("type"),JS_STR("mousewheel")); - evt->Set(JS_STR("wheelDeltaX"),JS_INT(xoffset*120)); - evt->Set(JS_STR("wheelDeltaY"),JS_INT(yoffset*120)); - evt->Set(JS_STR("wheelDelta"),JS_INT(yoffset*120)); + evt->Set(JS_STR("wheelDeltaX"),JS_NUM(xoffset*120)); + evt->Set(JS_STR("wheelDeltaY"),JS_NUM(yoffset*120)); + evt->Set(JS_STR("wheelDelta"),JS_NUM(yoffset*120)); - Handle argv[2] = { + Local argv[2] = { JS_STR("mousewheel"), // event name evt }; @@ -435,9 +437,9 @@ void APIENTRY scrollCB(GLFWwindow *window, double xoffset, double yoffset) { } int APIENTRY windowCloseCB() { - NanScope(); + Nan::HandleScope scope; - Handle argv[1] = { + Local argv[1] = { JS_STR("quit"), // event name }; @@ -447,21 +449,21 @@ int APIENTRY windowCloseCB() { } NAN_METHOD(testJoystick) { - NanScope(); + Nan::HandleScope scope; - int width = args[0]->Uint32Value(); - int height = args[1]->Uint32Value(); + int width = info[0]->Uint32Value(); + int height = info[1]->Uint32Value(); float ratio = width / (float) height; - float translateX = args[2]->NumberValue(); - float translateY = args[3]->NumberValue(); - float translateZ = args[4]->NumberValue(); + float translateX = info[2]->NumberValue(); + float translateY = info[3]->NumberValue(); + float translateZ = info[4]->NumberValue(); - float rotateX = args[5]->NumberValue(); - float rotateY = args[6]->NumberValue(); - float rotateZ = args[7]->NumberValue(); + float rotateX = info[5]->NumberValue(); + float rotateY = info[6]->NumberValue(); + float rotateZ = info[7]->NumberValue(); - float angle = args[8]->NumberValue(); + float angle = info[8]->NumberValue(); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); @@ -484,14 +486,14 @@ NAN_METHOD(testJoystick) { glVertex3f(0.f, 0.6f, 0.f); glEnd(); - NanReturnUndefined(); + return; } NAN_METHOD(testScene) { - NanScope(); - int width = args[0]->Uint32Value(); - int height = args[1]->Uint32Value(); - float z = args.Length()>2 ? (float) args[2]->NumberValue() : 0; + Nan::HandleScope scope; + int width = info[0]->Uint32Value(); + int height = info[1]->Uint32Value(); + float z = info.Length()>2 ? (float) info[2]->NumberValue() : 0; float ratio = width / (float) height; glViewport(0, 0, width, height); @@ -514,28 +516,28 @@ NAN_METHOD(testScene) { glVertex3f(0.f+z, 0.6f, 0.f); glEnd(); - NanReturnUndefined(); + return; } NAN_METHOD(WindowHint) { - NanScope(); - int target = args[0]->Uint32Value(); - int hint = args[1]->Uint32Value(); + Nan::HandleScope scope; + int target = info[0]->Uint32Value(); + int hint = info[1]->Uint32Value(); glfwWindowHint(target, hint); - NanReturnUndefined(); + return; } NAN_METHOD(DefaultWindowHints) { - NanScope(); + Nan::HandleScope scope; glfwDefaultWindowHints(); - NanReturnUndefined(); + return; } NAN_METHOD(JoystickPresent) { - NanScope(); - int joy = args[0]->Uint32Value(); + Nan::HandleScope scope; + int joy = info[0]->Uint32Value(); bool isPresent = glfwJoystickPresent(joy); - NanReturnValue(JS_BOOL(isPresent)); + info.GetReturnValue().Set(JS_BOOL(isPresent)); } std::string intToString(int number) { @@ -556,8 +558,8 @@ std::string buttonToString(unsigned char c) { } NAN_METHOD(GetJoystickAxes) { - NanScope(); - int joy = args[0]->Uint32Value(); + Nan::HandleScope scope; + int joy = info[0]->Uint32Value(); int count; const float *axisValues = glfwGetJoystickAxes(joy, &count); string response = ""; @@ -566,12 +568,12 @@ NAN_METHOD(GetJoystickAxes) { response.append(","); //Separator } - NanReturnValue(JS_STR(response.c_str())); + info.GetReturnValue().Set(JS_STR(response.c_str())); } NAN_METHOD(GetJoystickButtons) { - NanScope(); - int joy = args[0]->Uint32Value(); + Nan::HandleScope scope; + int joy = info[0]->Uint32Value(); int count = 0; const unsigned char* response = glfwGetJoystickButtons(joy, &count); @@ -581,30 +583,30 @@ NAN_METHOD(GetJoystickButtons) { strResponse.append(","); } - NanReturnValue(JS_STR(strResponse.c_str())); + info.GetReturnValue().Set(JS_STR(strResponse.c_str())); } NAN_METHOD(GetJoystickName) { - NanScope(); - int joy = args[0]->Uint32Value(); + Nan::HandleScope scope; + int joy = info[0]->Uint32Value(); const char* response = glfwGetJoystickName(joy); - NanReturnValue(JS_STR(response)); + info.GetReturnValue().Set(JS_STR(response)); } NAN_METHOD(glfw_CreateWindow) { - NanScope(); - int width = args[0]->Uint32Value(); - int height = args[1]->Uint32Value(); - String::Utf8Value str(args[2]->ToString()); - int monitor_idx = args[3]->Uint32Value(); + Nan::HandleScope scope; + int width = info[0]->Uint32Value(); + int height = info[1]->Uint32Value(); + String::Utf8Value str(info[2]->ToString()); + int monitor_idx = info[3]->Uint32Value(); GLFWwindow* window = NULL; GLFWmonitor **monitors = NULL, *monitor = NULL; int monitor_count; - if(args.Length() >= 4 && monitor_idx >= 0){ + if(info.Length() >= 4 && monitor_idx >= 0){ monitors = glfwGetMonitors(&monitor_count); if(monitor_idx >= monitor_count){ - return NanThrowError("Invalid monitor"); + return Nan::ThrowError("Invalid monitor"); } monitor = monitors[monitor_idx]; } @@ -614,7 +616,7 @@ NAN_METHOD(glfw_CreateWindow) { if(!window) { // can't create window, throw error - return NanThrowError("Can't create GLFW window"); + return Nan::ThrowError("Can't create GLFW window"); } glfwMakeContextCurrent(window); @@ -631,7 +633,7 @@ NAN_METHOD(glfw_CreateWindow) { msg+=")"; fprintf(stderr, "%s", msg.c_str()); - return NanThrowError(msg.c_str()); + return Nan::ThrowError(msg.c_str()); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); } @@ -639,7 +641,7 @@ NAN_METHOD(glfw_CreateWindow) { glfwSetWindowSize(window, width,height); // Set callback functions - NanAssignPersistent(glfw_events, args.This()->Get(JS_STR("events"))->ToObject()); + glfw_events.Reset( info.This()->Get(JS_STR("events"))->ToObject()); // window callbacks glfwSetWindowPosCallback( window, windowPosCB ); @@ -658,268 +660,268 @@ NAN_METHOD(glfw_CreateWindow) { glfwSetCursorEnterCallback( window, cursorEnterCB ); glfwSetScrollCallback( window, scrollCB ); - NanReturnValue(JS_NUM((uint64_t) window)); + info.GetReturnValue().Set(JS_NUM((uint64_t) window)); } NAN_METHOD(DestroyWindow) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwDestroyWindow(window); } - NanReturnUndefined(); + return; } NAN_METHOD(SetWindowTitle) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - String::Utf8Value str(args[1]->ToString()); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + String::Utf8Value str(info[1]->ToString()); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwSetWindowTitle(window, *str); } - NanReturnUndefined(); + return; } NAN_METHOD(GetWindowSize) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { int w,h; GLFWwindow* window = reinterpret_cast(handle); glfwGetWindowSize(window, &w, &h); - Local arr=Array::New(2); + Local arr=Nan::New(2); arr->Set(JS_STR("width"),JS_INT(w)); arr->Set(JS_STR("height"),JS_INT(h)); - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } - NanReturnUndefined(); + return; } NAN_METHOD(SetWindowSize) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - glfwSetWindowSize(window, args[1]->Uint32Value(),args[2]->Uint32Value()); + glfwSetWindowSize(window, info[1]->Uint32Value(),info[2]->Uint32Value()); } - NanReturnUndefined(); + return; } NAN_METHOD(SetWindowPos) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - glfwSetWindowPos(window, args[1]->Uint32Value(),args[2]->Uint32Value()); + glfwSetWindowPos(window, info[1]->Uint32Value(),info[2]->Uint32Value()); } - NanReturnUndefined(); + return; } NAN_METHOD(GetWindowPos) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); int xpos, ypos; glfwGetWindowPos(window, &xpos, &ypos); - Local arr=Array::New(2); + Local arr=Nan::New(2); arr->Set(JS_STR("xpos"),JS_INT(xpos)); arr->Set(JS_STR("ypos"),JS_INT(ypos)); - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } - NanReturnUndefined(); + return; } NAN_METHOD(GetFramebufferSize) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); int width, height; glfwGetFramebufferSize(window, &width, &height); - Local arr=Array::New(2); + Local arr=Nan::New(2); arr->Set(JS_STR("width"),JS_INT(width)); arr->Set(JS_STR("height"),JS_INT(height)); - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } - NanReturnUndefined(); + return; } NAN_METHOD(IconifyWindow) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwIconifyWindow(window); } - NanReturnUndefined(); + return; } NAN_METHOD(RestoreWindow) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwRestoreWindow(window); } - NanReturnUndefined(); + return; } NAN_METHOD(HideWindow) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwHideWindow(window); } - NanReturnUndefined(); + return; } NAN_METHOD(ShowWindow) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwShowWindow(window); } - NanReturnUndefined(); + return; } NAN_METHOD(WindowShouldClose) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - NanReturnValue(JS_INT(glfwWindowShouldClose(window))); + info.GetReturnValue().Set(JS_INT(glfwWindowShouldClose(window))); } - NanReturnUndefined(); + return; } NAN_METHOD(SetWindowShouldClose) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - int value=args[1]->Uint32Value(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + int value=info[1]->Uint32Value(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwSetWindowShouldClose(window, value); } - NanReturnUndefined(); + return; } NAN_METHOD(GetWindowAttrib) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - int attrib=args[1]->Uint32Value(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + int attrib=info[1]->Uint32Value(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - NanReturnValue(JS_INT(glfwGetWindowAttrib(window, attrib))); + info.GetReturnValue().Set(JS_INT(glfwGetWindowAttrib(window, attrib))); } - NanReturnUndefined(); + return; } NAN_METHOD(PollEvents) { - NanScope(); + Nan::HandleScope scope; glfwPollEvents(); - NanReturnUndefined(); + return; } NAN_METHOD(WaitEvents) { - NanScope(); + Nan::HandleScope scope; glfwWaitEvents(); - NanReturnUndefined(); + return; } /* Input handling */ NAN_METHOD(GetKey) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - int key=args[1]->Uint32Value(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + int key=info[1]->Uint32Value(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - NanReturnValue(JS_INT(glfwGetKey(window, key))); + info.GetReturnValue().Set(JS_INT(glfwGetKey(window, key))); } - NanReturnUndefined(); + return; } NAN_METHOD(GetMouseButton) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - int button=args[1]->Uint32Value(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + int button=info[1]->Uint32Value(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); - NanReturnValue(JS_INT(glfwGetMouseButton(window, button))); + info.GetReturnValue().Set(JS_INT(glfwGetMouseButton(window, button))); } - NanReturnUndefined(); + return; } NAN_METHOD(GetCursorPos) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); double x,y; glfwGetCursorPos(window, &x, &y); - Local arr=Array::New(2); - arr->Set(JS_STR("x"),JS_INT(x)); - arr->Set(JS_STR("y"),JS_INT(y)); - NanReturnValue(arr); + Local arr=Nan::New(2); + arr->Set(JS_STR("x"),JS_NUM(x)); + arr->Set(JS_STR("y"),JS_NUM(y)); + info.GetReturnValue().Set(arr); } - NanReturnUndefined(); + return; } NAN_METHOD(SetCursorPos) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); - int x=args[1]->NumberValue(); - int y=args[2]->NumberValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); + int x=info[1]->NumberValue(); + int y=info[2]->NumberValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwSetCursorPos(window, x, y); } - NanReturnUndefined(); + return; } /* @Module Context handling */ NAN_METHOD(MakeContextCurrent) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwMakeContextCurrent(window); } - NanReturnUndefined(); + return; } NAN_METHOD(GetCurrentContext) { - NanScope(); + Nan::HandleScope scope; GLFWwindow* window=glfwGetCurrentContext(); - NanReturnValue(JS_NUM((uint64_t) window)); + info.GetReturnValue().Set(JS_NUM((uint64_t) window)); } NAN_METHOD(SwapBuffers) { - NanScope(); - uint64_t handle=args[0]->IntegerValue(); + Nan::HandleScope scope; + uint64_t handle=info[0]->IntegerValue(); if(handle) { GLFWwindow* window = reinterpret_cast(handle); glfwSwapBuffers(window); } - NanReturnUndefined(); + return; } NAN_METHOD(SwapInterval) { - NanScope(); - int interval=args[0]->Int32Value(); + Nan::HandleScope scope; + int interval=info[0]->Int32Value(); glfwSwapInterval(interval); - NanReturnUndefined(); + return; } /* Extension support */ NAN_METHOD(ExtensionSupported) { - NanScope(); - String::AsciiValue str(args[0]->ToString()); - NanReturnValue(JS_BOOL(glfwExtensionSupported(*str)==1)); + Nan::HandleScope scope; + String::Utf8Value str(info[0]->ToString()); + info.GetReturnValue().Set(JS_BOOL(glfwExtensionSupported(*str)==1)); } // make sure we close everything when we exit @@ -936,13 +938,14 @@ void AtExit() { // /////////////////////////////////////////////////////////////////////////////// #define JS_GLFW_CONSTANT(name) target->Set(JS_STR( #name ), JS_INT(GLFW_ ## name)) -#define JS_GLFW_SET_METHOD(name) NODE_SET_METHOD(target, #name , glfw::name); +#define JS_GLFW_SET_METHOD(name) Nan::SetMethod(target, #name , glfw::name); extern "C" { -void init(Handle target) { +NAN_MODULE_INIT(init) +{ atexit(glfw::AtExit); - NanScope(); + Nan::HandleScope scope; /* GLFW initialization, termination and version querying */ JS_GLFW_SET_METHOD(Init); @@ -959,7 +962,7 @@ void init(Handle target) { /* Window handling */ //JS_GLFW_SET_METHOD(CreateWindow); - NODE_SET_METHOD(target, "CreateWindow", glfw::glfw_CreateWindow); + Nan::SetMethod(target, "CreateWindow", glfw::glfw_CreateWindow); JS_GLFW_SET_METHOD(WindowHint); JS_GLFW_SET_METHOD(DefaultWindowHints); JS_GLFW_SET_METHOD(DestroyWindow);