Created
July 8, 2014 04:18
-
-
Save g-1/fa0d61b2ceccac77e3b9 to your computer and use it in GitHub Desktop.
JSBでC++のmapをJavascriptのオブジェクトとして返す方法 ref: http://qiita.com/g-1/items/7d52cef20e37ccf5dd2c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSObject *object = JS_NewObject(_cx, NULL, NULL, NULL ); | |
JSBool result = JS_TRUE; | |
std::map< std::string, std::string >::const_iterator it = params.begin(); | |
while(it != params.end()){ | |
CCLOG("%s => %s",it->first.c_str(), it->second.c_str()); | |
JSString* jsValue = JS_NewStringCopyN(_cx, it->second.c_str(), it->second.length()); | |
result &= JS_DefineProperty(_cx, object, it->first.c_str(), STRING_TO_JSVAL(jsValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); | |
++it; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment