From 02d2282b83477bbc8a0fa788cd372d557be0fa4f Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 12 Sep 2014 17:07:06 +0800 Subject: [PATCH] add ui::Editbox lua binding, deprecated cc.EditBox to ccui.EditBox --- .../lua_cocos2dx_extension_manual.cpp | 104 ----------------- .../manual/ui/lua_cocos2dx_ui_manual.cpp | 109 +++++++++++++++++- .../extension/DeprecatedExtensionClass.lua | 21 +++- .../project/Classes/lua_module_register.h | 3 +- tools/tolua/cocos2dx_ui.ini | 4 +- 5 files changed, 129 insertions(+), 112 deletions(-) diff --git a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp index 80498ab073..48a3eda657 100644 --- a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp @@ -356,110 +356,7 @@ static void extendControl(lua_State* tolua_S) lua_pop(tolua_S, 1); } -static int tolua_cocos2d_EditBox_registerScriptEditBoxHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - EditBox* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"cc.EditBox",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(tolua_S,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); - self->registerScriptEditBoxHandler(handler); - return 0; - } - - CCLOG("%s function of EditBox has wrong number of arguments: %d, was expecting %d\n", "cc.EditBox:registerScriptEditBoxHandler", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler(lua_State* tolua_S) -{ - - if (NULL == tolua_S) - return 0; - - int argc = 0; - EditBox* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"cc.EditBox",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(tolua_S,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - self->unregisterScriptEditBoxHandler(); - return 0; - } - - CCLOG("%s function of EditBox has wrong number of arguments: %d, was expecting %d\n", "cc.EditBox:unregisterScriptEditBoxHandler", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'.",&tolua_err); - return 0; -#endif -} - -static void extendEditBox(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "cc.EditBox"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"registerScriptEditBoxHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_EditBox_registerScriptEditBoxHandler ); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S,"unregisterScriptEditBoxHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler ); - lua_rawset(tolua_S,-3); - } - lua_pop(tolua_S, 1); -} class LuaAssetsManagerDelegateProtocol:public Ref, public AssetsManagerDelegateProtocol { @@ -1045,7 +942,6 @@ static void extendTableView(lua_State* L) int register_all_cocos2dx_extension_manual(lua_State* tolua_S) { extendControl(tolua_S); - /* extendEditBox(tolua_S); */ extendAssetsManager(tolua_S); extendScrollView(tolua_S); extendTableView(tolua_S); diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp index c118218d58..4318a9173f 100644 --- a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp @@ -671,6 +671,112 @@ static void extendLayoutParameter(lua_State* L) lua_pop(L, 1); } + +static int tolua_cocos2d_EditBox_registerScriptEditBoxHandler(lua_State* tolua_S) +{ + if (NULL == tolua_S) + return 0; + + int argc = 0; + EditBox* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'\n", NULL); + return 0; + } +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + self->registerScriptEditBoxHandler(handler); + return 0; + } + + CCLOG("%s function of EditBox has wrong number of arguments: %d, was expecting %d\n", "ccui.EditBox:registerScriptEditBoxHandler", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_EditBox_registerScriptEditBoxHandler'.",&tolua_err); + return 0; +#endif + +} + +static int tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler(lua_State* tolua_S) +{ + + if (NULL == tolua_S) + return 0; + + int argc = 0; + EditBox* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"ccui.EditBox",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'\n", NULL); + return 0; + } +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (0 == argc) + { + self->unregisterScriptEditBoxHandler(); + return 0; + } + + CCLOG("%s function of EditBox has wrong number of arguments: %d, was expecting %d\n", "ccui.EditBox:unregisterScriptEditBoxHandler", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler'.",&tolua_err); + return 0; +#endif +} + +static void extendEditBox(lua_State* tolua_S) +{ + lua_pushstring(tolua_S, "ccui.EditBox"); + lua_rawget(tolua_S, LUA_REGISTRYINDEX); + if (lua_istable(tolua_S,-1)) + { + lua_pushstring(tolua_S,"registerScriptEditBoxHandler"); + lua_pushcfunction(tolua_S,tolua_cocos2d_EditBox_registerScriptEditBoxHandler ); + lua_rawset(tolua_S,-3); + lua_pushstring(tolua_S,"unregisterScriptEditBoxHandler"); + lua_pushcfunction(tolua_S,tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler ); + lua_rawset(tolua_S,-3); + } + lua_pop(tolua_S, 1); +} + int register_all_cocos2dx_ui_manual(lua_State* L) { if (nullptr == L) @@ -683,7 +789,8 @@ int register_all_cocos2dx_ui_manual(lua_State* L) extendScrollView(L); extendListView(L); extendLayoutParameter(L); - + extendEditBox(L); + return 0; } diff --git a/cocos/scripting/lua-bindings/script/extension/DeprecatedExtensionClass.lua b/cocos/scripting/lua-bindings/script/extension/DeprecatedExtensionClass.lua index 03cc96c49e..62093cafbc 100644 --- a/cocos/scripting/lua-bindings/script/extension/DeprecatedExtensionClass.lua +++ b/cocos/scripting/lua-bindings/script/extension/DeprecatedExtensionClass.lua @@ -17,10 +17,17 @@ _G["CCControl"] = DeprecatedExtensionClass.CCControl() --CCEditBox class will be Deprecated,begin function DeprecatedExtensionClass.CCEditBox() - deprecatedTip("CCEditBox","cc.EditBox") - return cc.EditBox + deprecatedTip("CCEditBox","ccui.EditBox") + return ccui.EditBox end _G["CCEditBox"] = DeprecatedExtensionClass.CCEditBox() + +function DeprecatedExtensionClass.CCUIEditBox() + deprecatedTip("cc.EditBox","ccui.EditBox") + return ccui.EditBox +end +_G["cc"]["EditBox"] = DeprecatedExtensionClass.CCUIEditBox() + --CCEditBox class will be Deprecated,end --CCScrollView class will be Deprecated,begin @@ -97,10 +104,16 @@ _G["CCControlButton"] = DeprecatedExtensionClass.CCControlButton() --CCScale9Sprite class will be Deprecated,begin function DeprecatedExtensionClass.CCScale9Sprite() - deprecatedTip("CCScale9Sprite","cc.Scale9Sprite") - return cc.Scale9Sprite + deprecatedTip("CCScale9Sprite","ccui.Scale9Sprite") + return ccui.Scale9Sprite end _G["CCScale9Sprite"] = DeprecatedExtensionClass.CCScale9Sprite() + +function DeprecatedExtensionClass.UIScale9Sprite() + deprecatedTip("cc.Scale9Sprite","ccui.Scale9Sprite") + return ccui.Scale9Sprite +end +_G["cc"]["Scale9Sprite"] = DeprecatedExtensionClass.UIScale9Sprite() --CCScale9Sprite class will be Deprecated,end --CCControlColourPicker class will be Deprecated,begin diff --git a/tests/lua-tests/project/Classes/lua_module_register.h b/tests/lua-tests/project/Classes/lua_module_register.h index 36ce8dff3c..fe82f59e1e 100644 --- a/tests/lua-tests/project/Classes/lua_module_register.h +++ b/tests/lua-tests/project/Classes/lua_module_register.h @@ -14,10 +14,11 @@ int lua_module_register(lua_State* L) { + register_ui_moudle(L); + //extension module must be registed after ui module register_extension_module(L); register_cocostudio_module(L); register_cocosbuilder_module(L); - register_ui_moudle(L); register_spine_module(L); register_network_module(L); register_cocosdenshion_module(L); diff --git a/tools/tolua/cocos2dx_ui.ini b/tools/tolua/cocos2dx_ui.ini index 90258ae875..a609e52e70 100644 --- a/tools/tolua/cocos2dx_ui.ini +++ b/tools/tolua/cocos2dx_ui.ini @@ -30,7 +30,7 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox Scale9Sprite +classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox Scale9Sprite EditBox # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -39,7 +39,7 @@ classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text T # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener (s|g)etBlendFunc ccTouch.*], +skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener (s|g)etBlendFunc ccTouch.* (g|s)etDelegate], Widget::[(s|g)etUserObject], Layer::[getInputManager], LayoutParameter::[(s|g)etMargin],