Skip to content

Commit

Permalink
Binding ResouceData structure to js to fix auto compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofeng11 committed Nov 19, 2015
1 parent 5369f9a commit 32f21ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
41 changes: 41 additions & 0 deletions cocos/scripting/js-bindings/manual/js_manual_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "js_manual_conversions.h"
#include "cocos2d_specifics.hpp"
#include "math/TransformUtils.h"
#include "2d/CocosStudioExtension.h"

USING_NS_CC;

Expand Down Expand Up @@ -2865,3 +2866,43 @@ jsval std_map_string_string_to_jsval(JSContext* cx, const std::map<std::string,
}
return OBJECT_TO_JSVAL(jsRet);
}

bool jsval_to_resoucedata(JSContext *cx, JS::HandleValue v, ResouceData* ret) {
JS::RootedObject tmp(cx);
JS::RootedValue jstype(cx);
JS::RootedValue jsfile(cx);
JS::RootedValue jsplist(cx);

double t = 0;
std::string file, plist;
bool ok = v.isObject() &&
JS_ValueToObject(cx, v, &tmp) &&
JS_GetProperty(cx, tmp, "type", &jstype) &&
JS_GetProperty(cx, tmp, "name", &jsfile) &&
JS_GetProperty(cx, tmp, "plist", &jsplist) &&
JS::ToNumber(cx, jstype, &t) &&
jsval_to_std_string(cx, jsfile, &file) &&
jsval_to_std_string(cx, jsplist, &plist);

JSB_PRECONDITION3(ok, cx, false, "Error processing arguments");

ret->type = (int)t;
ret->file = file;
ret->plist = plist;
return true;
}

jsval resoucedata_to_jsval(JSContext* cx, const ResouceData& v)
{
JS::RootedObject proto(cx);
JS::RootedObject parent(cx);
JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent));
if (!tmp) return JSVAL_NULL;
bool ok = JS_DefineProperty(cx, tmp, "type", v.type, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "file", JS::RootedValue(cx, std_string_to_jsval(cx, v.file)), JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "plist", JS::RootedValue(cx, std_string_to_jsval(cx, v.plist)), JSPROP_ENUMERATE | JSPROP_PERMANENT);
if (ok) {
return OBJECT_TO_JSVAL(tmp);
}
return JSVAL_NULL;
}
6 changes: 6 additions & 0 deletions cocos/scripting/js-bindings/manual/js_manual_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#define JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES

NS_CC_BEGIN
struct CC_DLL ResouceData;
NS_CC_END

// just a simple utility to avoid mem leaking when using JSString
class JSStringWrapper
{
Expand Down Expand Up @@ -110,6 +114,7 @@ bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, cocos2d::__
bool jsval_to_quaternion(JSContext *cx, JS::HandleValue vp, cocos2d::Quaternion* ret);
bool jsval_to_obb(JSContext *cx, JS::HandleValue vp, cocos2d::OBB* ret);
bool jsval_to_ray(JSContext *cx, JS::HandleValue vp, cocos2d::Ray* ret);
bool jsval_to_resoucedata(JSContext *cx, JS::HandleValue v, ResouceData* ret);

// forward declaration
js_proxy_t* jsb_get_js_proxy(JSObject* jsObj);
Expand Down Expand Up @@ -272,6 +277,7 @@ jsval FontDefinition_to_jsval(JSContext* cx, const cocos2d::FontDefinition& t);
jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q);
jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q);
jsval uniform_to_jsval(JSContext* cx, const cocos2d::Uniform* uniform);
jsval resoucedata_to_jsval(JSContext* cx, const ResouceData& v);

template<class T>
js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj);
Expand Down
2 changes: 1 addition & 1 deletion tools/bindings-generator
Submodule bindings-generator updated 1 files
+2 −0 targets/spidermonkey/conversions.yaml

0 comments on commit 32f21ca

Please sign in to comment.