Operations on js global variables.
1. Modify the value.
In this example,. js contains a global variable x. Now we get x to c ++. This is a string.
[Cpp] jsval x;
JS_GetProperty (SC-> getGlobalContext (), SC-> getGlobalObject (), "x", & x );
JSString * pS = JS_ValueToString (ScriptingCore: getInstance ()-> getGlobalContext (), x );
JSStringWrapper pW (pS );
CCLog (pW. get (). c_str ());
Jsval x;
JS_GetProperty (SC-> getGlobalContext (), SC-> getGlobalObject (), "x", & x );
JSString * pS = JS_ValueToString (ScriptingCore: getInstance ()-> getGlobalContext (), x );
JSStringWrapper pW (pS );
CCLog (pW. get (). c_str ());
2. Get the value.
Another example is that there is a global variable x in. js. Now we use c ++ to set the value to HelloWorld!
[Cpp] jsval x = c_string_to_jsval (SC-> getGlobalContext (), "HelloWorld! ");
JS_SetProperty (SC-> getGlobalContext (), SC-> getGlobalObject (), "x", & x );
Jsval x = c_string_to_jsval (SC-> getGlobalContext (), "HelloWorld! ");
JS_SetProperty (SC-> getGlobalContext (), SC-> getGlobalObject (), "x", & x );
To be continued... complicated Arry and Object.