adds "require" to the global namespace

This commit is contained in:
Rolando Abarca 2012-05-21 16:08:34 -07:00
parent 8196324e38
commit bed6efa3cd
4 changed files with 6 additions and 0 deletions

View File

@ -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;
}

View File

@ -0,0 +1,3 @@
require("JS/1to1/test_require_second.js");
cocos.log("value: " + value);

View File

@ -0,0 +1 @@
value = "this was set in another file";

View File

@ -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);