Cocos2d-x spridemonkey JavaScript interaction with C ++ (2)-single global variable operation

Source: Internet
Author: User

Wow, I 've found many posts recently. I wrote some stuff this Friday. Now it's all over the street. My brother doesn't ask for fame or fortune. I feel pretty good. I'm also very happy to hear about Js ~ Haha. It was about to get off work. This article was written in a rush. Now it's better.

First understand SC-> getglobalobject ()... this student asked me .. you are not scientific... SC is a wool... that's what this guy said. you can't blame me. this is coming to work. sorry .... pu GE has always said to be happy with his mind. well. right. hope for this in a week .... okay. SC is the cocos2d-x package for us that single key .. students who have used it. and those who have read the source code will certainly know that cocos2d-x has a lot of single keys .. what is the director. XXX, right .. scriptingcore * SC = scriptingcore: getinstance ();
About the JS core class of the entire cocos2d-x is this stuff. scriptingcore. the root jsobject and JS context can be obtained through this operation. these two very important things. the following example is. get the variable X under the root node. the following things are very easy to understand.

1. js global variable operations.

1. Modify the value.

In this example,. js contains a global variable X. Now we get X to C ++. This is a string.

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!

 
Jsval x = c_string_to_jsval (SC-> getglobalcontext (), "helloworld! "); Js_setproperty (SC-> getglobalcontext (), SC-> getglobalobject ()," X ", & X );

To be continued... complicated arry and object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.