Skip to content

Instantly share code, notes, and snippets.

@g-1
Created July 8, 2014 04:18
Show Gist options
  • Save g-1/fa0d61b2ceccac77e3b9 to your computer and use it in GitHub Desktop.
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
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