Skip to content

Commit

Permalink
Merge pull request #31 from cocoscodeide/master
Browse files Browse the repository at this point in the history
update runtime js
  • Loading branch information
chuanweizhang2013 committed Jul 2, 2014
2 parents 8c0d2c6 + 9d16910 commit 57dc9c5
Show file tree
Hide file tree
Showing 34 changed files with 401 additions and 196 deletions.
46 changes: 18 additions & 28 deletions frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3581,13 +3581,13 @@ getMouseButton : function (
},

/**
* @method getScrollY
* @return {float}
* @method setMouseButton
* @param {int} arg0
*/
getScrollY : function (
setMouseButton : function (
int
)
{
return 0;
},

/**
Expand All @@ -3613,13 +3613,23 @@ getCursorY : function (
},

/**
* @method setMouseButton
* @param {int} arg0
* @method getCursorX
* @return {float}
*/
setMouseButton : function (
int
getCursorX : function (
)
{
return 0;
},

/**
* @method getScrollY
* @return {float}
*/
getScrollY : function (
)
{
return 0;
},

/**
Expand All @@ -3644,16 +3654,6 @@ getScrollX : function (
return 0;
},

/**
* @method getCursorX
* @return {float}
*/
getCursorX : function (
)
{
return 0;
},

/**
* @method EventMouse
* @constructor
Expand All @@ -3672,16 +3672,6 @@ mouseeventtype
*/
cc.EventListenerMouse = {

/**
* @method create
* @return {cc.EventListenerMouse}
*/
create : function (
)
{
return cc.EventListenerMouse;
},

};

/**
Expand Down
105 changes: 41 additions & 64 deletions frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8956,21 +8956,24 @@ bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval *
JS_ReportError(cx, "js_cocos2dx_EventMouse_getMouseButton : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp)
bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
bool ok = true;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollY : Invalid Native Object");
if (argc == 0) {
double ret = cobj->getScrollY();
jsval jsret = JSVAL_NULL;
jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Invalid Native Object");
if (argc == 1) {
int arg0;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Error processing arguments");
cobj->setMouseButton(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return true;
}

JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollY : wrong number of arguments: %d, was expecting %d", argc, 0);
JS_ReportError(cx, "js_cocos2dx_EventMouse_setMouseButton : wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *vp)
Expand Down Expand Up @@ -9012,24 +9015,38 @@ bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp)
JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorY : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp)
bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
bool ok = true;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Invalid Native Object");
if (argc == 1) {
int arg0;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventMouse_setMouseButton : Error processing arguments");
cobj->setMouseButton(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorX : Invalid Native Object");
if (argc == 0) {
double ret = cobj->getCursorX();
jsval jsret = JSVAL_NULL;
jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return true;
}

JS_ReportError(cx, "js_cocos2dx_EventMouse_setMouseButton : wrong number of arguments: %d, was expecting %d", argc, 1);
JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorX : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getScrollY : Invalid Native Object");
if (argc == 0) {
double ret = cobj->getScrollY();
jsval jsret = JSVAL_NULL;
jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return true;
}

JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollY : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsval *vp)
Expand Down Expand Up @@ -9071,23 +9088,6 @@ bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp)
JS_ReportError(cx, "js_cocos2dx_EventMouse_getScrollX : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::EventMouse* cobj = (cocos2d::EventMouse *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventMouse_getCursorX : Invalid Native Object");
if (argc == 0) {
double ret = cobj->getCursorX();
jsval jsret = JSVAL_NULL;
jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return true;
}

JS_ReportError(cx, "js_cocos2dx_EventMouse_getCursorX : wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
bool js_cocos2dx_EventMouse_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
Expand Down Expand Up @@ -9143,14 +9143,14 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) {
};

static JSFunctionSpec funcs[] = {
JS_FN("getMouseButton", js_cocos2dx_EventMouse_getMouseButton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getScrollY", js_cocos2dx_EventMouse_getScrollY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getButton", js_cocos2dx_EventMouse_getMouseButton, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setButton", js_cocos2dx_EventMouse_setMouseButton, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setScrollData", js_cocos2dx_EventMouse_setScrollData, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getLocationY", js_cocos2dx_EventMouse_getCursorY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setMouseButton", js_cocos2dx_EventMouse_setMouseButton, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getLocationX", js_cocos2dx_EventMouse_getCursorX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getScrollY", js_cocos2dx_EventMouse_getScrollY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setLocation", js_cocos2dx_EventMouse_setCursorPosition, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getScrollX", js_cocos2dx_EventMouse_getScrollX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getLocationX", js_cocos2dx_EventMouse_getCursorX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};

Expand Down Expand Up @@ -9187,26 +9187,6 @@ void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global) {
JSClass *jsb_cocos2d_EventListenerMouse_class;
JSObject *jsb_cocos2d_EventListenerMouse_prototype;

bool js_cocos2dx_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp)
{
if (argc == 0) {
cocos2d::EventListenerMouse* ret = cocos2d::EventListenerMouse::create();
jsval jsret = JSVAL_NULL;
do {
if (ret) {
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::EventListenerMouse>(cx, (cocos2d::EventListenerMouse*)ret);
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return true;
}
JS_ReportError(cx, "js_cocos2dx_EventListenerMouse_create : wrong number of arguments");
return false;
}


extern JSObject *jsb_cocos2d_EventListener_prototype;

Expand Down Expand Up @@ -9236,10 +9216,7 @@ void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global) {
JS_FS_END
};

static JSFunctionSpec st_funcs[] = {
JS_FN("create", js_cocos2dx_EventListenerMouse_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;

jsb_cocos2d_EventListenerMouse_prototype = JS_InitClass(
cx, global,
Expand Down
7 changes: 3 additions & 4 deletions frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,13 @@ void js_cocos2dx_EventMouse_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_EventMouse(JSContext *cx, JSObject *global);
void register_all_cocos2dx(JSContext* cx, JSObject* obj);
bool js_cocos2dx_EventMouse_getMouseButton(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_setScrollData(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getCursorY(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_setMouseButton(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getScrollY(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_setCursorPosition(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getScrollX(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_getCursorX(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventMouse_EventMouse(JSContext *cx, uint32_t argc, jsval *vp);

extern JSClass *jsb_cocos2d_EventListenerMouse_class;
Expand All @@ -503,7 +503,6 @@ bool js_cocos2dx_EventListenerMouse_constructor(JSContext *cx, uint32_t argc, js
void js_cocos2dx_EventListenerMouse_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_EventListenerMouse(JSContext *cx, JSObject *global);
void register_all_cocos2dx(JSContext* cx, JSObject* obj);
bool js_cocos2dx_EventListenerMouse_create(JSContext *cx, uint32_t argc, jsval *vp);

extern JSClass *jsb_cocos2d_EventAcceleration_class;
extern JSObject *jsb_cocos2d_EventAcceleration_prototype;
Expand Down
68 changes: 67 additions & 1 deletion frameworks/js-bindings/bindings/manual/ScriptingCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ static std::string getTouchFuncName(EventTouch::EventCode eventCode)
return funcName;
}

static std::string getMouseFuncName(EventMouse::MouseEventType eventType)
{
std::string funcName;
switch(eventType) {
case EventMouse::MouseEventType::MOUSE_DOWN:
funcName = "onMouseDown";
break;
case EventMouse::MouseEventType::MOUSE_UP:
funcName = "onMouseUp";
break;
case EventMouse::MouseEventType::MOUSE_MOVE:
funcName = "onMouseMove";
break;
case EventMouse::MouseEventType::MOUSE_SCROLL:
funcName = "onMouseScroll";
break;
default:
CCASSERT(false, "Invalid event code!");
}

return funcName;
}

static void rootObject(JSContext *cx, JSObject *obj) {
JS_AddNamedObjectRoot(cx, &obj, "unnamed");
}
Expand Down Expand Up @@ -1092,6 +1115,49 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event
return ret;
}

bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet/* = nullptr*/)
{
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET

std::string funcName = getMouseFuncName(eventType);
bool ret = false;

do
{
js_proxy_t * p = jsb_get_native_proxy(nativeObj);
if (!p) break;

jsval dataVal[1];
dataVal[0] = getJSObject(_cx, event);

if (jsvalRet != nullptr)
{
ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet);
}
else
{
jsval retval;
executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, &retval);
if(JSVAL_IS_NULL(retval))
{
ret = false;
}
else if(JSVAL_IS_BOOLEAN(retval))
{
ret = JSVAL_TO_BOOLEAN(retval);
}
else
{
ret = false;
}
}
} while(false);

removeJSObject(_cx, event);

return ret;
}

bool ScriptingCore::executeFunctionWithObjectData(void* nativeObj, const char *name, JSObject *obj) {

js_proxy_t * p = jsb_get_native_proxy(nativeObj);
Expand Down Expand Up @@ -1497,7 +1563,7 @@ static void serverEntryPoint(void)

char buf[1024] = {0};
int readBytes = 0;
while ((readBytes = ::recv(clientSocket, buf, sizeof(buf), 0)) > 0)
while ((readBytes = (int)::recv(clientSocket, buf, sizeof(buf), 0)) > 0)
{
buf[readBytes] = '\0';
// TRACE_DEBUGGER_SERVER("debug server : received command >%s", buf);
Expand Down
1 change: 1 addition & 0 deletions frameworks/js-bindings/bindings/manual/ScriptingCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class ScriptingCore : public cocos2d::ScriptEngineProtocol

bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event, jsval* jsvalRet = nullptr);
bool handleTouchEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, cocos2d::Touch* touch, cocos2d::Event* event, jsval* jsvalRet = nullptr);
bool handleMouseEvent(void* nativeObj, cocos2d::EventMouse::MouseEventType eventType, cocos2d::Event* event, jsval* jsvalRet = nullptr);
bool handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard::KeyCode keyCode, bool isPressed, cocos2d::Event* event);
};

Expand Down
3 changes: 3 additions & 0 deletions frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,9 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerTouchAllAtOnce; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_EventListenerTouchAllAtOnce_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);

tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerMouse; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_EventListenerMouse_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);

tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.EventListenerKeyboard; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_EventListenerKeyboard_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);

Expand Down
Loading

0 comments on commit 57dc9c5

Please sign in to comment.