From bed6efa3cd0d8822b7f132f52660b1d76d4851c1 Mon Sep 17 00:00:00 2001 From: Rolando Abarca Date: Mon, 21 May 2012 16:08:34 -0700 Subject: [PATCH] adds "require" to the global namespace --- testjs/Classes/AppDelegate.cpp | 1 + testjs/JS/1to1/test_require.js | 3 +++ testjs/JS/1to1/test_require_second.js | 1 + testjs/JSBindings/ScriptingCore.cpp | 1 + 4 files changed, 6 insertions(+) create mode 100644 testjs/JS/1to1/test_require.js create mode 100644 testjs/JS/1to1/test_require_second.js diff --git a/testjs/Classes/AppDelegate.cpp b/testjs/Classes/AppDelegate.cpp index 5f4cb520df..3179e73b87 100644 --- a/testjs/Classes/AppDelegate.cpp +++ b/testjs/Classes/AppDelegate.cpp @@ -110,6 +110,7 @@ bool AppDelegate::applicationDidFinishLaunching() // ScriptingCore::getInstance().runScript("JS/1to1/test_sound.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_bindings.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_transitions.js"); +// ScriptingCore::getInstance().runScript("JS/1to1/test_require.js"); return true; } diff --git a/testjs/JS/1to1/test_require.js b/testjs/JS/1to1/test_require.js new file mode 100644 index 0000000000..d44f70cd20 --- /dev/null +++ b/testjs/JS/1to1/test_require.js @@ -0,0 +1,3 @@ +require("JS/1to1/test_require_second.js"); + +cocos.log("value: " + value); diff --git a/testjs/JS/1to1/test_require_second.js b/testjs/JS/1to1/test_require_second.js new file mode 100644 index 0000000000..eeb76c56ab --- /dev/null +++ b/testjs/JS/1to1/test_require_second.js @@ -0,0 +1 @@ +value = "this was set in another file"; diff --git a/testjs/JSBindings/ScriptingCore.cpp b/testjs/JSBindings/ScriptingCore.cpp index 6802bfc5d6..a82f4e883d 100644 --- a/testjs/JSBindings/ScriptingCore.cpp +++ b/testjs/JSBindings/ScriptingCore.cpp @@ -207,6 +207,7 @@ ScriptingCore::ScriptingCore() S_SimpleAudioEngine::jsCreateClass(this->cx, cocos, "SimpleAudioEngine"); // register some global functions + JS_DefineFunction(this->cx, global, "require", ScriptingCore::executeScript, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "executeScript", ScriptingCore::executeScript, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "addGCRootObject", ScriptingCore::addRootJS, 1, JSPROP_READONLY | JSPROP_PERMANENT);