From a2e99202880aee7827e204220f281de5c43e7570 Mon Sep 17 00:00:00 2001 From: samuele3 Date: Mon, 18 Nov 2013 22:16:49 +0800 Subject: [PATCH] Hot fix:Repair some lua test samples and modify layer touch listener functions --- .../lua/bindings/lua_cocos2dx_manual.cpp | 3559 ----------------- .../lua_cocos2dx_manual.cpp.REMOVED.git-id | 1 + .../luaScript/ExtensionTest/ExtensionTest.lua | 3 +- .../Resources/luaScript/MenuTest/MenuTest.lua | 8 +- .../UserDefaultTest/UserDefaultTest.lua | 1 + 5 files changed, 8 insertions(+), 3564 deletions(-) delete mode 100644 cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp create mode 100644 cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp deleted file mode 100644 index 39083ae1e3..0000000000 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp +++ /dev/null @@ -1,3559 +0,0 @@ -#include "lua_cocos2dx_auto.hpp" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - -#include "cocos2d.h" -#include "LuaBasicConversions.h" -#include "LuaScriptHandlerMgr.h" -#include "CCLuaValue.h" - -static int tolua_cocos2d_MenuItemImage_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"MenuItemImage",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - do { - if (argc == 0) - { - MenuItemImage* tolua_ret = (MenuItemImage*)MenuItemImage::create(); - //Uncheck - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemImage"); - return 1; - } - } while (0); - do { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isstring(tolua_S,2,0,&tolua_err) || - !tolua_isstring(tolua_S,3,0,&tolua_err)) - { - ok = false; - } -#endif - if (!ok) - { - ok = true; - break; - } - const std::string normalImage = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string selectedImage = ((const std::string) tolua_tocppstring(tolua_S,3,0)); - MenuItemImage* tolua_ret = (MenuItemImage*) MenuItemImage::create(normalImage,selectedImage); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemImage"); - return 1; - - } while (0); - do { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isstring(tolua_S,2,0,&tolua_err) || - !tolua_isstring(tolua_S,3,0,&tolua_err) || - !tolua_isstring(tolua_S,4,0,&tolua_err) ) - { - goto tolua_lerror; - break; - } -#endif - const std::string normalImage = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string selectedImage = ((const std::string) tolua_tocppstring(tolua_S,3,0)); - const std::string disabledImage = ((const std::string) tolua_tocppstring(tolua_S,4,0)); - - MenuItemImage* tolua_ret = (MenuItemImage*) MenuItemImage::create(normalImage,selectedImage,disabledImage); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemImage"); - return 1; - - } while (0); - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_MenuItemImage_create'.\n",&tolua_err); -#endif - return 0; - -} - -static int tolua_cocos2d_MenuItemLabel_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"MenuItemLabel",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - if(1 == argc) - { - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,2,"Node",0,&tolua_err) ) - { - goto tolua_lerror; - } -#endif - Node* label = ((Node*) tolua_tousertype(tolua_S,2,0)); - MenuItemLabel* tolua_ret = (MenuItemLabel*) MenuItemLabel::create(label); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemLabel"); - return 1; - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_MenuItemFont_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"MenuItemFont",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - if(1 == argc) - { - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isstring(tolua_S, 2, 0, &tolua_err)) - { - goto tolua_lerror; - } -#endif - const std::string value = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - MenuItemFont* tolua_ret = (MenuItemFont*) MenuItemFont::create(value); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemFont"); - return 1; - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_MenuItemSprite_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"MenuItemSprite",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if(argc >= 2 && argc <= 3) - { - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,2,"Node",0,&tolua_err) || - !tolua_isusertype(tolua_S,3,"Node",0,&tolua_err) ) - { - goto tolua_lerror; - } - - if (3 == argc && !tolua_isusertype(tolua_S,4,"Node",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - - Node* normalSprite = ((Node*) tolua_tousertype(tolua_S,2,0)); - Node* selectedSprite = ((Node*) tolua_tousertype(tolua_S,3,0)); - Node* disabledSprite = NULL; - if (3 == argc) - { - disabledSprite = (Node*) tolua_tousertype(tolua_S,4,0); - } - MenuItemSprite* tolua_ret = (MenuItemSprite*) MenuItemSprite::create(normalSprite,selectedSprite,disabledSprite); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemSprite"); - return 1; - } - - CCLOG("create has wrong number of arguments: %d, was expecting %d\n", argc, 3); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Menu_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"Menu",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - if (argc > 0 ) - { - cocos2d::Array* array = cocos2d::Array::create(); - if (NULL == array) - { - CCLOG("Menu create method create array fail\n"); - return 0; - } - uint32_t i = 1; - while (i <= argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, 1 + i, "MenuItem", 0, &tolua_err)) - goto tolua_lerror; -#endif - - cocos2d::Object* item = static_cast(tolua_tousertype(tolua_S, 1 + i, NULL)); - if (NULL != item) - { - array->addObject(item); - ++i; - } - - } - cocos2d::Menu* tolua_ret = cocos2d::Menu::createWithArray(array); - //UnCheck - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Menu"); - return 1; - } - else if(argc == 0) - { - cocos2d::Menu* tolua_ret = cocos2d::Menu::create(); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Menu"); - return 1; - } - - CCLOG("create wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_Menu_create'.\n",&tolua_err); -#endif - return 0; -} - - - -static int tolua_cocos2dx_Menu_alignItemsInRows(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Menu* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Menu",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 'lua_cocos2dx_Menu_alignItemsInRows'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (argc > 0) - { - Array* array = NULL; - if (luavals_variadic_to_array(tolua_S, argc, &array)) - { - self->alignItemsInRowsWithArray(array); - } - return 0; - } - - CCLOG("'alignItemsInRows' has wrong number of arguments in tolua_cocos2dx_Menu_alignItemsInRows: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'alignItemsInRows'.\n",&tolua_err); -#endif - return 0; -} - -static int tolua_cocos2dx_Menu_alignItemsInColumns(lua_State* tolua_S) -{ - - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Menu* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Menu",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_cocos2dx_Menu_alignItemsInColumns'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (argc > 0) - { - Array* array = NULL; - if (luavals_variadic_to_array(tolua_S, argc, &array)) - { - self->alignItemsInColumnsWithArray(array); - } - return 0; - } - - CCLOG("'alignItemsInColumns' has wrong number of arguments in tolua_cocos2dx_Menu_alignItemsInColumns: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'alignItemsInColumns'.\n",&tolua_err); -#endif - return 0; -} - -static int tolua_cocos2d_MenuItemToggle_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"MenuItemToggle",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - if(argc >= 1) - { - MenuItemToggle* tolua_ret = MenuItemToggle::create(); - if (NULL == tolua_ret) - { - return 0; - } - - for (uint32_t i = 0; i < argc; ++i) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, i + 2,"MenuItem",0,&tolua_err) ) - { - goto tolua_lerror; - } -#endif - MenuItem* item = static_cast(tolua_tousertype(tolua_S, i + 2,0)); - if (0 == i) - { - tolua_ret->initWithItem(item); - } - else - { - tolua_ret->addSubItem(item); - } - } - - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemToggle"); - return 1; - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_MenuItem_registerScriptTapHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - MenuItem* cobj = nullptr; -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"MenuItem",0,&tolua_err)) goto tolua_lerror; -#endif - cobj = static_cast(tolua_tousertype(tolua_S,1,0)); -#if COCOS2D_DEBUG >= 1 - if (nullptr == cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'tolua_cocos2d_MenuItem_registerScriptTapHandler'\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)); - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)cobj, handler, ScriptHandlerMgr::HandlerType::MENU_CLICKED); - return 0; - } - - CCLOG("'registerScriptTapHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'registerScriptTapHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_MenuItem_unregisterScriptTapHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - MenuItem* cobj = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"MenuItem",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = static_cast(tolua_tousertype(tolua_S,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'tolua_cocos2d_MenuItem_unregisterScriptTapHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)cobj, ScriptHandlerMgr::HandlerType::MENU_CLICKED); - return 0; - } - - CCLOG("'unregisterScriptTapHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unregisterScriptTapHandler'.",&tolua_err); - return 0; -#endif -} - - -static int executeScriptTouchHandler(Layer* layer, EventTouch::EventCode eventType, Touch* touch) -{ - TouchScriptData data(eventType, layer, touch); - ScriptEvent event(kTouchEvent, &data); - return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); -} - -static int executeScriptTouchesHandler(Layer* layer, EventTouch::EventCode eventType, const std::vector& touches) -{ - TouchesScriptData data(eventType, layer, touches); - ScriptEvent event(kTouchesEvent, &data); - return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); -} - -static void setTouchEnabledForLayer(Layer* layer, bool enabled) -{ - if (nullptr == layer) - return; - - auto dict = static_cast(layer->getUserObject()); - if (dict == nullptr) - { - dict = Dictionary::create(); - layer->setUserObject(dict); - } - - dict->setObject(Bool::create(enabled), "touchEnabled"); - - auto touchListenerAllAtOnce = static_cast(dict->objectForKey("touchListenerAllAtOnce")); - auto touchListenerOneByOne = static_cast(dict->objectForKey("touchListenerOneByOne")); - auto touchMode = static_cast(dict->objectForKey("touchMode")); - auto swallowTouches = static_cast(dict->objectForKey("swallowTouches")); - - auto dispatcher = layer->getEventDispatcher(); - if (nullptr != dispatcher) - { - dispatcher->removeEventListener(touchListenerAllAtOnce); - dispatcher->removeEventListener(touchListenerOneByOne); - } - - if (enabled) - { - if (touchMode == nullptr || touchMode->getValue() == (int)Touch::DispatchMode::ALL_AT_ONCE) - { - auto listener = EventListenerTouchAllAtOnce::create(); - listener->onTouchesBegan = [layer](const std::vector& touches, Event* event){ - executeScriptTouchesHandler(layer, EventTouch::EventCode::BEGAN, touches); - }; - listener->onTouchesMoved = [layer](const std::vector& touches, Event* event){ - executeScriptTouchesHandler(layer, EventTouch::EventCode::MOVED, touches); - }; - listener->onTouchesEnded = [layer](const std::vector& touches, Event* event){ - executeScriptTouchesHandler(layer, EventTouch::EventCode::ENDED, touches); - }; - listener->onTouchesCancelled = [layer](const std::vector& touches, Event* event){ - executeScriptTouchesHandler(layer, EventTouch::EventCode::CANCELLED, touches); - }; - - dispatcher->addEventListenerWithSceneGraphPriority(listener, layer); - - dict->setObject(listener, "touchListenerAllAtOnce"); - } - else - { - auto listener = EventListenerTouchOneByOne::create(); - listener->setSwallowTouches(swallowTouches ? swallowTouches->getValue() : false); - listener->onTouchBegan = [layer](Touch* touch, Event* event) -> bool{ - return executeScriptTouchHandler(layer, EventTouch::EventCode::BEGAN, touch) == 0 ? false : true; - }; - listener->onTouchMoved = [layer](Touch* touch, Event* event){ - executeScriptTouchHandler(layer, EventTouch::EventCode::MOVED, touch); - }; - listener->onTouchEnded = [layer](Touch* touch, Event* event){ - executeScriptTouchHandler(layer, EventTouch::EventCode::ENDED, touch); - }; - listener->onTouchCancelled = [layer](Touch* touch, Event* event){ - executeScriptTouchHandler(layer, EventTouch::EventCode::CANCELLED, touch); - }; - - dispatcher->addEventListenerWithSceneGraphPriority(listener, layer); - - dict->setObject(listener, "touchListenerOneByOne"); - } - } - -} - -//Only for v2.x lua compatibility -static int lua_cocos2dx_Layer_setTouchPriority(lua_State* L) -{ - return 0; -} - -static int lua_cocos2dx_Layer_setTouchEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setTouchEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(L, 2, 0, &tolua_err)) - { - goto tolua_lerror; - } -#endif - bool enabled = tolua_toboolean(L, 2, 0); - setTouchEnabledForLayer(self, enabled); - return 0; - } - - CCLOG("'setTouchEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setTouchEnabled'.",&tolua_err); - return 0; -#endif - -} - -static int lua_cocos2dx_Layer_isTouchEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_isTouchEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - Bool* enabled = static_cast(dict->objectForKey("touchEnabled")); - bool ret = enabled ? enabled->getValue() : false; - tolua_pushboolean(L, ret); - return 1; - } - - return 0; - } - - CCLOG("'isTouchEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'isTouchEnabled'.",&tolua_err); - return 0; -#endif - - -} - -static int lua_cocos2dx_Layer_setTouchMode(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setTouchMode'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(L, 2, 0, &tolua_err)) - { - goto tolua_lerror; - } -#endif - int32_t mode = (int32_t)tolua_tonumber(L, 2, 0); - - auto dict = static_cast(self->getUserObject()); - if ( nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - - Integer* touchModeObj = static_cast(dict->objectForKey("touchMode")); - int32_t touchMode = touchModeObj ? touchModeObj->getValue() : 0; - if (touchMode != mode) - { - dict->setObject(Integer::create(mode), "touchMode"); - Bool* enabled = static_cast(dict->objectForKey("touchEnabled")); - if (enabled && enabled->getValue()) - { - setTouchEnabledForLayer(self, false); - setTouchEnabledForLayer(self, true); - } - } - return 0; - } - - CCLOG("'setTouchMode' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setTouchMode'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_getTouchMode(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_getTouchMode'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (0 == argc) - { - int32_t ret = 0; - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - Integer* mode = static_cast(dict->objectForKey("touchMode")); - ret = mode ? mode->getValue() : 0; - tolua_pushnumber(L, (lua_Number)ret); - return 1; - } - - return 0; - } - - CCLOG("'getTouchMode' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'getTouchMode'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_setSwallowsTouches(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setSwallowsTouches'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(L, 2, 0, &tolua_err)) - goto tolua_lerror; -#endif - - bool swallowsTouches = tolua_toboolean(L, 2, 0); - Bool* swallowsTouchesObj = nullptr; - - auto dict = static_cast(self->getUserObject()); - if (dict == nullptr) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - - swallowsTouchesObj = static_cast(dict->objectForKey("swallowTouches")); - bool oldSwallowsTouches = swallowsTouchesObj ? swallowsTouchesObj->getValue() : false; - - if (oldSwallowsTouches != swallowsTouches) - { - dict->setObject(Integer::create(swallowsTouches), "swallowTouches"); - Bool* enabled = static_cast(dict->objectForKey("touchEnabled")); - if (enabled && enabled->getValue()) - { - setTouchEnabledForLayer(self, false); - setTouchEnabledForLayer(self, true); - } - } - - return 0; - } - - CCLOG("'setSwallowsTouches' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setSwallowsTouches'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_isSwallowsTouches(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_isSwallowsTouches'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - Bool* swallowTouches = static_cast(dict->objectForKey("swallowTouches")); - bool ret = swallowTouches ? swallowTouches->getValue() : false; - lua_pushboolean(L, ret); - return 1; - } - return 0; - } - - CCLOG("'isSwallowsTouches' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'isSwallowsTouches'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_setKeyboardEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setKeyboardEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(L, 2, 0, &tolua_err)) - goto tolua_lerror; -#endif - bool enabled = tolua_toboolean(L, 2, 0); - auto dict = static_cast(self->getUserObject()); - if (dict == nullptr) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - - dict->setObject(Bool::create(enabled), "keyboardEnabled"); - - auto keyboardListener = static_cast(dict->objectForKey("keyboardListener")); - - auto dispatcher = self->getEventDispatcher(); - dispatcher->removeEventListener(keyboardListener); - if (enabled) - { - auto listener = EventListenerKeyboard::create(); - listener->onKeyPressed = [self](EventKeyboard::KeyCode keyCode, Event* event){ - - }; - listener->onKeyReleased = [self](EventKeyboard::KeyCode keyCode, Event* event){ - KeypadScriptData data(keyCode, self); - ScriptEvent scriptEvent(kKeypadEvent,&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); - }; - CCLOG("come in the keyboardEnable"); - dispatcher->addEventListenerWithSceneGraphPriority(listener, self); - - dict->setObject(listener, "keyboardListener"); - } - return 0; - } - - CCLOG("'setKeyboardEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setKeyboardEnabled'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_isKeyboardEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_isKeyboardEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - Bool* enabled = static_cast(dict->objectForKey("keyboardEnabled")); - bool ret = enabled ? enabled->getValue() : false; - tolua_pushboolean(L, ret); - return 1; - } - return 0; - } - - CCLOG("'isKeyboardEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'isKeyboardEnabled'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_setAccelerometerEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setAccelerometerEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(L, 2, 0, &tolua_err)) - goto tolua_lerror; -#endif - bool enabled = tolua_toboolean(L, 2, 0); - auto dict = static_cast(self->getUserObject()); - if (dict == nullptr) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - - dict->setObject(Bool::create(enabled), "accelerometerEnabled"); - - auto accListener = static_cast(dict->objectForKey("accListener")); - - auto dispatcher = self->getEventDispatcher(); - dispatcher->removeEventListener(accListener); - - Device::setAccelerometerEnabled(enabled); - - if (enabled) - { - auto listener = EventListenerAcceleration::create([self](Acceleration* acc, Event* event){ - BasicScriptData data(self,(void*)acc); - ScriptEvent accEvent(kAccelerometerEvent,&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&accEvent); - }); - - dispatcher->addEventListenerWithSceneGraphPriority(listener, self); - - dict->setObject(listener, "accListener"); - } - - return 0; - } - - CCLOG("'setAccelerometerEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setAccelerometerEnabled'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_isAccelerometerEnabled(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_isAccelerometerEnabled'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - Bool* enabled = static_cast(dict->objectForKey("accelerometerEnabled")); - bool ret = enabled ? enabled->getValue() : false; - tolua_pushboolean(L, ret); - return 1; - } - - return 0; - } - - - CCLOG("'isAccelerometerEnabled' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'isAccelerometerEnabled'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_Layer_setAccelerometerInterval(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Layer",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Layer_setAccelerometerInterval'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(L, 2, 0, &tolua_err)) - goto tolua_lerror; -#endif - double interval = tolua_tonumber(L, 2, 0); - Device::setAccelerometerEnabled(interval); - return 0; - } - - CCLOG("'setAccelerometerInterval' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setAccelerometerInterval'.",&tolua_err); - return 0; -#endif -} - - -static int tolua_cocos2d_Layer_registerScriptTouchHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_registerScriptTouchHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc >=1 && argc <= 4) { -#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)); - bool isMultiTouches = false; - //Note:priority is useless - int priority = 0; - bool swallowTouches = true; - - if (argc >= 2) { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(tolua_S,3,0,&tolua_err)) { - goto tolua_lerror; - } -#endif - isMultiTouches = (bool)tolua_toboolean(tolua_S,3,false); - } - - if (argc >= 3) { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,4,0,&tolua_err)) { - goto tolua_lerror; - } -#endif - priority = (int)tolua_tonumber(tolua_S,4,0); - } - - if (argc == 4) { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isboolean(tolua_S,5,0,&tolua_err)) { - goto tolua_lerror; - } -#endif - swallowTouches = (bool)tolua_toboolean(tolua_S,5,true); - } - - Touch::DispatchMode touchesMode = Touch::DispatchMode::ALL_AT_ONCE; - if (!isMultiTouches) - touchesMode = Touch::DispatchMode::ONE_BY_ONE; - - auto dict = static_cast(self->getUserObject()); - if (dict == nullptr) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - - auto touchModeobj = static_cast(dict->objectForKey("touchMode")); - auto swallowTouchesValue = static_cast(dict->objectForKey("swallowTouches")); - - //touch model - int32_t mode = touchModeobj?touchModeobj->getValue() : 0; - if (mode != (int)touchesMode) - { - dict->setObject(Integer::create((int)touchesMode), "touchMode"); - Bool* enabled = static_cast(dict->objectForKey("touchEnabled")); - if (enabled && enabled->getValue()) - { - setTouchEnabledForLayer(self, false); - setTouchEnabledForLayer(self, true); - } - } - - //swallowsTouches Obj - bool oldSwallowTouchesValue = swallowTouchesValue?swallowTouchesValue->getValue():false; - if (oldSwallowTouchesValue != swallowTouches) - { - dict->setObject(Integer::create(swallowTouches), "swallowTouches"); - Bool* enabled = static_cast(dict->objectForKey("touchEnabled")); - if (enabled && enabled->getValue()) - { - setTouchEnabledForLayer(self, false); - setTouchEnabledForLayer(self, true); - } - } - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::TOUCHES); - return 0; - } - - CCLOG("'registerScriptTouchHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'registerScriptTouchHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Layer_unregisterScriptTouchHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_unregisterScriptTouchHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - auto touchListenerAllAtOnce = static_cast(dict->objectForKey("touchListenerAllAtOnce")); - auto touchListenerOneByOne = static_cast(dict->objectForKey("touchListenerOneByOne")); - auto dispatcher = self->getEventDispatcher(); - if (nullptr != dispatcher) - { - dispatcher->removeEventListener(touchListenerAllAtOnce); - dispatcher->removeEventListener(touchListenerOneByOne); - } - } - - ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, ScriptHandlerMgr::HandlerType::TOUCHES); - return 0; - } - - CCLOG("'unregisterScriptTouchHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unregisterScriptTapHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Layer_registerScriptKeypadHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_registerScriptKeypadHandler'\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)); - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::KEYPAD); - return 0; - } - - CCLOG("'registerScriptKeypadHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'registerScriptKeypadHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Layer_unregisterScriptKeypadHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_unregisterScriptKeypadHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - auto keyboardListener = static_cast(dict->objectForKey("keyboardListener")); - - auto dispatcher = self->getEventDispatcher(); - if (dispatcher != nullptr) - { - dispatcher->removeEventListener(keyboardListener); - } - } - - ScriptHandlerMgr::getInstance()->removeObjectHandler(self, ScriptHandlerMgr::HandlerType::KEYPAD); - return 0; - } - - CCLOG("'unregisterScriptKeypadHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unregisterScriptKeypadHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Layer_registerScriptAccelerateHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_registerScriptAccelerateHandler'\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)); - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::ACCELEROMETER); - return 0; - } - - CCLOG("'registerScriptAccelerateHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'registerScriptAccelerateHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Layer_unregisterScriptAccelerateHandler(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Layer* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Layer",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_Layer_unregisterScriptAccelerateHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - auto dict = static_cast(self->getUserObject()); - if (dict != nullptr) - { - auto accListener = static_cast(dict->objectForKey("accListener")); - - auto dispatcher = self->getEventDispatcher(); - if (dispatcher != nullptr) - { - dispatcher->removeEventListener(accListener); - } - } - - ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, ScriptHandlerMgr::HandlerType::ACCELEROMETER); - return 0; - } - - CCLOG("'unregisterScriptAccelerateHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unregisterScriptAccelerateHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Scheduler_scheduleScriptFunc(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Scheduler* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Scheduler",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_Scheduler_scheduleScriptFunc'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (3 == argc) { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) || - !tolua_isnumber(tolua_S,3,0,&tolua_err) || - !tolua_isboolean(tolua_S,4,0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); - float interval = (float) tolua_tonumber(tolua_S,3,0); - bool paused = (bool) tolua_toboolean(tolua_S,4,0); - unsigned int tolua_ret = (unsigned int) self->scheduleScriptFunc(handler,interval,paused); - tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); - return 1; - } - - CCLOG("'scheduleScriptFunc' has wrong number of arguments: %d, was expecting %d\n", argc, 3); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'scheduleScriptFunc'.",&tolua_err); - return 0; -#endif -} - - -static int tolua_cocos2d_Scheduler_unscheduleScriptEntry(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Scheduler* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Scheduler",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_Scheduler_unscheduleScriptEntry'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (1 == argc) { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - - unsigned int scheduleScriptEntryID = ((unsigned int) tolua_tonumber(tolua_S,2,0)); - self->unscheduleScriptEntry(scheduleScriptEntryID); - return 0; - } - - CCLOG("'unscheduleScriptEntry' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unscheduleScriptEntry'.",&tolua_err); - return 0; -#endif -} - -int tolua_cocos2d_Sequence_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"Sequence",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - if(argc > 0) - { - cocos2d::Array* array = cocos2d::Array::create(); - if (NULL == array) - { - CCLOG("Sequence create method create array fail\n"); - return 0; - } - uint32_t i = 1; - while (i <= argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, 1 + i, "Object", 0, &tolua_err)) - goto tolua_lerror; -#endif - - cocos2d::Object* item = static_cast(tolua_tousertype(tolua_S, 1 + i, NULL)); - if (NULL != item) - { - array->addObject(item); - ++i; - } - - } - cocos2d::Sequence* tolua_ret = cocos2d::Sequence::create(array); - //issue 2433 uncheck - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Sequence"); - return 1; - } - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_CallFunc_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"CallFunc",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 1) - { -#if COCOS2D_DEBUG >= 1 - if(!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) - goto tolua_lerror; -#endif - - LUA_FUNCTION funcID = ( toluafix_ref_function(tolua_S,2,0)); - LuaCallFunc* tolua_ret = (LuaCallFunc*) LuaCallFunc::create(funcID); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CallFunc"); - return 1; - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif - -} - -static int tolua_cocos2d_Node_registerScriptHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Node* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Node",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_Node_registerScriptHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 1) - { -#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)); - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::NODE); - - return 0; - } - - CCLOG("'registerScriptHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Node_unregisterScriptHandler(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Node* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Node",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_Node_unregisterScriptHandler'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 0) - { - ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, ScriptHandlerMgr::HandlerType::NODE); - return 0; - } - - CCLOG("'unregisterScriptHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unregisterScriptHandler'.",&tolua_err); - return 0; -#endif -} - - -static int tolua_Cocos2d_Node_scheduleUpdateWithPriorityLua(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Node* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Node",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_Node_scheduleUpdateWithPriorityLua'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 2) - { -#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)); - int priority = 0; - if (luaval_to_int32(tolua_S, 3, &priority)) - { - self->scheduleUpdateWithPriorityLua(handler,priority); - } - return 0; - } - - CCLOG("'scheduleUpdateWithPriorityLua' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'scheduleUpdateWithPriorityLua'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Node_unscheduleUpdate(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Node* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Node",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_Node_unscheduleUpdate'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - self->unscheduleUpdate(); - return 0; - } - - CCLOG("'unscheduleUpdate' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'unscheduleUpdate'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Node_getPosition(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - Node* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Node",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_Node_getPosition'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc >= 0 && argc <= 2) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,2,1,&tolua_err) || !tolua_isnumber(tolua_S,3,1,&tolua_err) ) - goto tolua_lerror; -#endif - float x = (float) tolua_tonumber(tolua_S,2,0); - float y = (float) tolua_tonumber(tolua_S,3,0); - - self->getPosition(&x,&y); - - tolua_pushnumber(tolua_S,(lua_Number)x); - tolua_pushnumber(tolua_S,(lua_Number)y); - - return 2; - } - - CCLOG("'getPosition' function in Node has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getPosition'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_Spawn_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"Spawn",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc > 0) - { - cocos2d::Array* array = cocos2d::Array::create(); - if (NULL == array) - { - CCLOG("Spawn create method create array fail\n"); - return 0; - } - - uint32_t i = 1; - while (i <= argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, 1 + i, "Object", 0, &tolua_err)) - goto tolua_lerror; -#endif - - cocos2d::Object* item = static_cast(tolua_tousertype(tolua_S, 1 + i, NULL)); - if (NULL != item) - { - array->addObject(item); - ++i; - } - } - - cocos2d::Spawn * tolua_ret = cocos2d::Spawn::create(array); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Spawn"); - return 1; - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -int lua_cocos2d_CardinalSplineBy_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"CardinalSplineBy",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 3) - { - double dur = 0.0; - ok &= luaval_to_number(tolua_S, 2, &dur); - if (!ok) - return false; - - int num = 0; - Point *arr = NULL; - ok &= luaval_to_array_of_Point(tolua_S, 3, &arr, &num); - if (!ok) - return false; - - double ten = 0.0; - ok &= luaval_to_number(tolua_S, 4, &ten); - if (!ok) - return false; - - if (num > 0) - { - PointArray* points = PointArray::create(num); - - if (NULL == points) - { - free(arr); - return 0; - } - - for( int i = 0; i < num; i++) { - points->addControlPoint(arr[i]); - } - - free(arr); - CardinalSplineBy* tolua_ret = CardinalSplineBy::create(dur, points, ten); - if (NULL != tolua_ret) - { - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CardinalSplineBy"); - return 1; - } - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 3); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -int tolua_cocos2d_CatmullRomBy_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"CatmullRomBy",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 2) - { - double dur = 0.0; - ok &= luaval_to_number(tolua_S, 2, &dur); - if (!ok) - return false; - - int num = 0; - Point *arr = NULL; - ok &= luaval_to_array_of_Point(tolua_S, 3, &arr, &num); - if (!ok) - return false; - - if (num > 0) - { - PointArray* points = PointArray::create(num); - - if (NULL == points) - { - free(arr); - return 0; - } - - for( int i = 0; i < num; i++) { - points->addControlPoint(arr[i]); - } - - free(arr); - CatmullRomBy* tolua_ret = CatmullRomBy::create(dur, points); - if (NULL != tolua_ret) - { - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CatmullRomBy"); - return 1; - } - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -int tolua_cocos2d_CatmullRomTo_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"CatmullRomTo",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 2) - { - double dur = 0.0; - ok &= luaval_to_number(tolua_S, 2, &dur); - if (!ok) - return false; - - int num = 0; - Point *arr = NULL; - ok &= luaval_to_array_of_Point(tolua_S, 3, &arr, &num); - if (!ok) - return false; - - if (num > 0) - { - PointArray* points = PointArray::create(num); - - if (NULL == points) - { - free(arr); - return 0; - } - - for( int i = 0; i < num; i++) { - points->addControlPoint(arr[i]); - } - - free(arr); - CatmullRomTo* tolua_ret = CatmullRomTo::create(dur, points); - if (NULL != tolua_ret) - { - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CatmullRomTo"); - return 1; - } - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -int tolua_cocos2d_BezierBy_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"BezierBy",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 2) - { - double t = 0.0; - ok &= luaval_to_number(tolua_S, 2, &t); - if (!ok) - return false; - - int num = 0; - Point *arr = NULL; - ok &= luaval_to_array_of_Point(tolua_S, 3, &arr, &num); - if (!ok) - return false; - - if (num < 3) - { - free(arr); - return false; - } - - ccBezierConfig config; - config.controlPoint_1 = arr[0]; - config.controlPoint_2 = arr[1]; - config.endPosition = arr[2]; - free(arr); - - BezierBy* tolua_ret = BezierBy::create(t, config); - if (NULL != tolua_ret) - { - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"BezierBy"); - return 1; - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -int tolua_cocos2d_BezierTo_create(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"BezierTo",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 2) - { - double t = 0.0; - ok &= luaval_to_number(tolua_S, 2, &t); - if (!ok) - return false; - - int num = 0; - Point *arr = NULL; - ok &= luaval_to_array_of_Point(tolua_S, 3, &arr, &num); - if (!ok) - return false; - - if (num < 3) - { - free(arr); - return false; - } - - ccBezierConfig config; - config.controlPoint_1 = arr[0]; - config.controlPoint_2 = arr[1]; - config.endPosition = arr[2]; - free(arr); - - BezierTo* tolua_ret = BezierTo::create(t, config); - if (NULL != tolua_ret) - { - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"BezierTo"); - return 1; - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2d_DrawNode_drawPolygon(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - DrawNode* self = nullptr; - - tolua_Error tolua_err; -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"DrawNode",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_DrawNode_drawPolygon'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (5 == argc) - { -#if COCOS2D_DEBUG >= 1 - if( - !tolua_istable(tolua_S, 2, 0, &tolua_err) || - !tolua_isnumber(tolua_S, 3, 0, &tolua_err) || - !tolua_istable(tolua_S, 4, 0,&tolua_err) || - !tolua_isnumber(tolua_S, 5, 0, &tolua_err) || - !tolua_istable(tolua_S,6, 0,&tolua_err) ) - { - goto tolua_lerror; - } -#endif - size_t size = lua_tonumber(tolua_S, 3); - if ( size > 0 ) - { - Point* points = new Point[size]; - if (NULL == points) - return 0; - - for (int i = 0; i < size; i++) - { - lua_pushnumber(tolua_S,i + 1); - lua_gettable(tolua_S,2); - if (!tolua_istable(tolua_S,-1, 0, &tolua_err)) - { - CC_SAFE_DELETE_ARRAY(points); -#if COCOS2D_DEBUG >= 1 - goto tolua_lerror; -#endif - } - - if(!luaval_to_point(tolua_S, lua_gettop(tolua_S), &points[i])) - { - lua_pop(tolua_S, 1); - CC_SAFE_DELETE_ARRAY(points); - return 0; - } - lua_pop(tolua_S, 1); - } - - Color4F fillColor; - if (!luaval_to_color4f(tolua_S, 4, &fillColor)) - { - CC_SAFE_DELETE_ARRAY(points); - return 0; - } - - float borderWidth = (float)tolua_tonumber(tolua_S, 5, 0); - - Color4F borderColor; - if (!luaval_to_color4f(tolua_S, 6, &borderColor)) - { - CC_SAFE_DELETE_ARRAY(points); - return 0; - } - - self->drawPolygon(points, size, fillColor, borderWidth, borderColor); - CC_SAFE_DELETE_ARRAY(points); - return 0; - } - } - - CCLOG("'drawPolygon' has wrong number of arguments: %d, was expecting %d\n", argc, 5); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'drawPolygon'.",&tolua_err); - return 0; -#endif -} - -// setBlendFunc -template -static int tolua_cocos2dx_setBlendFunc(lua_State* tolua_S,const char* className) -{ - if (NULL == tolua_S || NULL == className || strlen(className) == 0) - return 0; - - int argc = 0; - T* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,className,0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(tolua_S,1,0)); - - argc = lua_gettop(tolua_S) - 1; - if (2 == argc) - { - GLenum src, dst; - if (!luaval_to_int32(tolua_S, 2, (int32_t*)&src)) - return 0; - - if (!luaval_to_int32(tolua_S, 3, (int32_t*)&dst)) - return 0; - - BlendFunc blendFunc = {src, dst}; - self->setBlendFunc(blendFunc); - return 0; - } - - - CCLOG("'setBlendFunc' has wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'setBlendFunc'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_Sprite_setBlendFunc(lua_State* tolua_S) -{ - return tolua_cocos2dx_setBlendFunc(tolua_S,"Sprite"); -} - -static int tolua_cocos2dx_LayerColor_setBlendFunc(lua_State* tolua_S) -{ - return tolua_cocos2dx_setBlendFunc(tolua_S,"LayerColor"); -} - -static int tolua_cocos2dx_ParticleSystem_setBlendFunc(lua_State* tolua_S) -{ - return tolua_cocos2dx_setBlendFunc(tolua_S,"ParticleSystem"); -} - -static int tolua_cocos2dx_LayerMultiplex_create(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Array* array = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S, 1, "LayerMultiplex", 0, &tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc > 0) - { - if (luavals_variadic_to_array(tolua_S, argc, &array) && nullptr != array ) - { - LayerMultiplex* tolua_ret = LayerMultiplex::createWithArray(array); - int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"LayerMultiplex"); - return 1; - } - else - { - CCLOG("error in tolua_cocos2dx_LayerMultiplex_create \n"); - return 0; - } - } - - CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_Camera_getCenter(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Camera* self = nullptr; -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Camera",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_cocos2dx_Camera_getCenter'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - float x; - float y; - float z; - self->getCenter(&x, &y, &z); - tolua_pushnumber(tolua_S,(lua_Number)x); - tolua_pushnumber(tolua_S, (lua_Number)y); - tolua_pushnumber(tolua_S, (lua_Number)z); - return 3; - } - - CCLOG("'getCenter' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getCenter'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_Camera_getEye(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Camera* self = nullptr; -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Camera",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_cocos2dx_Camera_getEye'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - float x; - float y; - float z; - self->getEye(&x, &y, &z); - tolua_pushnumber(tolua_S,(lua_Number)x); - tolua_pushnumber(tolua_S, (lua_Number)y); - tolua_pushnumber(tolua_S, (lua_Number)z); - return 3; - } - - CCLOG("'getEye' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getEye'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_Camera_getUp(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Camera* self = nullptr; -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Camera",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_cocos2dx_Camera_getUp'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (0 == argc) - { - float x; - float y; - float z; - self->getUp(&x, &y, &z); - tolua_pushnumber(tolua_S,(lua_Number)x); - tolua_pushnumber(tolua_S, (lua_Number)y); - tolua_pushnumber(tolua_S, (lua_Number)z); - return 3; - } - - CCLOG("'getUp' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getUp'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_FileUtils_getStringFromFile(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - FileUtils* self = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"FileUtils",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_cocos2dx_FileUtils_getStringFromFile'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (1 == argc) - { - const char* arg0; - std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp); arg0 = arg0_tmp.c_str(); - if (ok) - { - std::string fullPathName = FileUtils::getInstance()->fullPathForFilename(arg0); - String* contentsOfFile = String::createWithContentsOfFile(fullPathName.c_str()); - if (nullptr != contentsOfFile) - { - const char* tolua_ret = contentsOfFile->getCString(); - tolua_pushstring(tolua_S, tolua_ret); - } - return 1; - } - } - - CCLOG("'getStringFromFile' has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getStringFromFile'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_UserDefault_getInstance(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"UserDefault",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if(0 == argc) - { - UserDefault* tolua_ret = (UserDefault*) UserDefault::getInstance(); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"UserDefault"); - return 1; - } - - CCLOG("'getInstance' has wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getInstance'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_GLProgram_create(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - bool ok = false; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"GLProgram",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if(2 == argc) - { - const char *arg0, *arg1; - std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= luaval_to_std_string(tolua_S, 3, &arg1_tmp); arg1 = arg1_tmp.c_str(); - - GLProgram* tolua_ret = new GLProgram(); - if (nullptr == tolua_ret) - return 0; - - tolua_ret->autorelease(); - tolua_ret->initWithVertexShaderFilename(arg0, arg1); - int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; - int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"GLProgram"); - return 1; - - } - - CCLOG("'create' function of GLProgram wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); - return 0; -#endif -} - - -static int tolua_cocos2d_GLProgram_getProgram(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - GLProgram* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"GLProgram",0,&tolua_err)) goto tolua_lerror; -#endif - - self = (GLProgram*) tolua_tousertype(tolua_S,1,0); -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_GLProgram_getProgram'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - if (0 == argc) - { - unsigned const int tolua_ret = ( unsigned const int) self->getProgram(); - tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); - return 1; - } - - CCLOG("'getProgram' function of GLProgram wrong number of arguments: %d, was expecting %d\n", argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'getProgram'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_GLProgram_setUniformLocationF32(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - GLProgram* self = nullptr; - int location = 0; - double f1 = 0.0; - double f2 = 0.0; - double f3 = 0.0; - double f4 = 0.0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"GLProgram",0,&tolua_err)) goto tolua_lerror; -#endif - - self = (GLProgram*) tolua_tousertype(tolua_S,1,0); -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_GLProgram_getProgram'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc >= 2 && argc <= 5) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isnumber(tolua_S,3,0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - - location = (int) tolua_tonumber(tolua_S,2,0); - f1 = (float) tolua_tonumber(tolua_S,3,0); - - if (2 == argc) - { - self->setUniformLocationWith1f(location,f1); - return 0; - } - - if (argc >= 3) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,4,0,&tolua_err)) - goto tolua_lerror; -#endif - - f2 = (float) tolua_tonumber(tolua_S,3,0); - if (3 == argc) - { - self->setUniformLocationWith2f(location, f1, f2); - return 0; - } - } - - if (argc >= 4) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,5,0,&tolua_err)) - goto tolua_lerror; -#endif - - f3 = (float) tolua_tonumber(tolua_S,3,0); - if (4 == argc) - { - self->setUniformLocationWith3f(location, f1, f2, f3); - return 0; - } - } - - if (argc == 5) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S,6,0,&tolua_err)) - goto tolua_lerror; -#endif - - f4 = (float) tolua_tonumber(tolua_S,3,0); - if (4 == argc) - { - self->setUniformLocationWith4f(location, f1, f2, f3, f4); - return 0; - } - - } - } - - CCLOG("'setUniformLocationF32' function of GLProgram wrong number of arguments: %d, was expecting %d\n", argc, 2); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'setUniformLocationF32'.",&tolua_err); - return 0; -#endif - -} - -static void extendGLProgram(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "GLProgram"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_GLProgram_create ); - lua_rawset(tolua_S,-3); - - lua_pushstring(tolua_S,"getProgram"); - lua_pushcfunction(tolua_S,tolua_cocos2d_GLProgram_getProgram ); - lua_rawset(tolua_S,-3); - - lua_pushstring(tolua_S,"setUniformLocationF32"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_GLProgram_setUniformLocationF32 ); - lua_rawset(tolua_S,-3); - } -} - -static int tolua_cocos2dx_Texture2D_setTexParameters(lua_State* tolua_S) -{ - if (nullptr == tolua_S) - return 0; - - int argc = 0; - Texture2D* self = nullptr; - GLuint arg1 = 0; - GLuint arg2 = 0; - GLuint arg3 = 0; - GLuint arg4 = 0; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Texture2D",0,&tolua_err)) goto tolua_lerror; -#endif - - self = (Texture2D*) tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) - { - tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_Texture2D_setTexParameters'\n", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (4 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err) || - !tolua_isnumber(tolua_S, 3, 0, &tolua_err) || - !tolua_isnumber(tolua_S, 4, 0, &tolua_err) || - !tolua_isnumber(tolua_S, 5, 0, &tolua_err)) - { - goto tolua_lerror; - } -#endif - - arg1 = (GLuint)tolua_tonumber(tolua_S, 2, 0); - arg2 = (GLuint)tolua_tonumber(tolua_S, 3, 0); - arg3 = (GLuint)tolua_tonumber(tolua_S, 4, 0); - arg4 = (GLuint)tolua_tonumber(tolua_S, 5, 0); - - Texture2D::TexParams param = { arg1, arg2, arg3, arg4 }; - - self->setTexParameters(param); - - return 0; - } - - CCLOG("'setTexParameters' function of Texture2D wrong number of arguments: %d, was expecting %d\n", argc,4); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'setTexParameters'.",&tolua_err); - return 0; -#endif -} - -static int tolua_cocos2dx_SpriteBatchNode_getDescendants(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - int argc = 0; - cocos2d::SpriteBatchNode* cobj = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"SpriteBatchNode",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = (cocos2d::SpriteBatchNode*)tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (!cobj) - { - tolua_error(tolua_S,"invalid 'cobj' in function 'tolua_cocos2dx_SpriteBatchNode_getDescendants'", NULL); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - return 0; - std::vector ret = cobj->getDescendants(); - - lua_newtable(tolua_S); - - if (ret.empty()) - return 1; - - auto iter = ret.begin(); - int indexTable = 1; - for (; iter != ret.end(); ++iter) - { - if (nullptr == *iter) - continue; - - lua_pushnumber(tolua_S, (lua_Number)indexTable); - toluafix_pushusertype_ccobject(tolua_S, (*iter)->_ID, &((*iter)->_luaID), (void*)(*iter),"Sprite"); - lua_rawset(tolua_S, -3); - (*iter)->retain(); - ++indexTable; - } - - return 1; - } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getDescendants",argc, 0); - return 0; -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteBatchNode_getDescendants'.",&tolua_err); -#endif - return 0; -} - -static void extendTexture2D(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "Texture2D"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"setTexParameters"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Texture2D_setTexParameters ); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenuItem(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"MenuItem"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"registerScriptTapHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItem_registerScriptTapHandler); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S, "unregisterScriptTapHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItem_unregisterScriptTapHandler); - lua_rawset(tolua_S, -3); - } -} - -static void extendMenuItemImage(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"MenuItemImage"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemImage_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenuItemLabel(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "MenuItemLabel"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemLabel_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenuItemFont(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "MenuItemFont"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemFont_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenuItemSprite(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "MenuItemSprite"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemSprite_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenuItemToggle(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "MenuItemToggle"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemToggle_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendMenu(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "Menu"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S, -1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Menu_create); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S,"alignItemsInRows"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Menu_alignItemsInRows); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S,"alignItemsInColumns"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Menu_alignItemsInColumns); - lua_rawset(tolua_S,-3); - } -} - -static void extendNode(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Node"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"registerScriptHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Node_registerScriptHandler); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S,"unregisterScriptHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Node_unregisterScriptHandler); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S,"scheduleUpdateWithPriorityLua"); - lua_pushcfunction(tolua_S,tolua_Cocos2d_Node_scheduleUpdateWithPriorityLua); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S,"unscheduleUpdate"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Node_unscheduleUpdate); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S,"getPosition"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Node_getPosition); - lua_rawset(tolua_S, -3); - } -} - -static void extendLayer(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Layer"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"registerScriptTouchHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Layer_registerScriptTouchHandler); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S, "unregisterScriptTouchHandler"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Layer_unregisterScriptTouchHandler); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S, "registerScriptKeypadHandler"); - lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_registerScriptKeypadHandler); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S, "unregisterScriptKeypadHandler"); - lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_unregisterScriptKeypadHandler); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S, "registerScriptAccelerateHandler"); - lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_registerScriptAccelerateHandler); - lua_rawset(tolua_S, -3); - lua_pushstring(tolua_S, "unregisterScriptAccelerateHandler"); - lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_unregisterScriptAccelerateHandler); - lua_rawset(tolua_S, -3); - - tolua_function(tolua_S, "setTouchEnabled", lua_cocos2dx_Layer_setTouchEnabled); - tolua_function(tolua_S, "isTouchEnabled", lua_cocos2dx_Layer_isTouchEnabled); - tolua_function(tolua_S, "setTouchMode", lua_cocos2dx_Layer_setTouchMode); - tolua_function(tolua_S, "getTouchMode", lua_cocos2dx_Layer_getTouchMode); - tolua_function(tolua_S, "setSwallowsTouches", lua_cocos2dx_Layer_setSwallowsTouches); - tolua_function(tolua_S, "isSwallowsTouches", lua_cocos2dx_Layer_isSwallowsTouches); - tolua_function(tolua_S, "setKeyboardEnabled", lua_cocos2dx_Layer_setKeyboardEnabled); - tolua_function(tolua_S, "isKeyboardEnabled", lua_cocos2dx_Layer_isKeyboardEnabled); - tolua_function(tolua_S, "setAccelerometerEnabled", lua_cocos2dx_Layer_setAccelerometerEnabled); - tolua_function(tolua_S, "isAccelerometerEnabled", lua_cocos2dx_Layer_isAccelerometerEnabled); - tolua_function(tolua_S, "setAccelerometerInterval", lua_cocos2dx_Layer_setAccelerometerInterval); - } -} - -static void extendScheduler(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Scheduler"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"scheduleScriptFunc"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Scheduler_scheduleScriptFunc); - lua_rawset(tolua_S,-3); - lua_pushstring(tolua_S, "unscheduleScriptEntry"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Scheduler_unscheduleScriptEntry); - lua_rawset(tolua_S, -3); - } -} - -static void extendSequence(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Sequence"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Sequence_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendCallFunc(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"CallFunc"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_CallFunc_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendSpawn(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Spawn"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_Spawn_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendCardinalSplineBy(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"CardinalSplineBy"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,lua_cocos2d_CardinalSplineBy_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendCatmullRomBy(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"CatmullRomBy"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_CatmullRomBy_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendCatmullRomTo(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"CatmullRomTo"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_CatmullRomTo_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendBezierBy(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"BezierBy"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_BezierBy_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendBezierTo(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"BezierTo"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2d_BezierTo_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendDrawNode(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"DrawNode"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"drawPolygon"); - lua_pushcfunction(tolua_S,tolua_cocos2d_DrawNode_drawPolygon); - lua_rawset(tolua_S,-3); - } -} - -static void extendSprite(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"Sprite"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"setBlendFunc"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Sprite_setBlendFunc); - lua_rawset(tolua_S,-3); - } -} - -static void extendLayerColor(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"LayerColor"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"setBlendFunc"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_LayerColor_setBlendFunc); - lua_rawset(tolua_S,-3); - } -} - -static void extendLayerMultiplex(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"LayerMultiplex"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"create"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_LayerMultiplex_create); - lua_rawset(tolua_S,-3); - } -} - -static void extendParticleSystem(lua_State* tolua_S) -{ - lua_pushstring(tolua_S,"ParticleSystem"); - lua_rawget(tolua_S,LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"setBlendFunc"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_ParticleSystem_setBlendFunc); - lua_rawset(tolua_S,-3); - } -} - -static void extendCamera(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "Camera"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"getCenter"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Camera_getCenter ); - lua_rawset(tolua_S,-3); - - lua_pushstring(tolua_S,"getUp"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Camera_getUp ); - lua_rawset(tolua_S,-3); - - lua_pushstring(tolua_S,"getEye"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_Camera_getEye ); - lua_rawset(tolua_S,-3); - } -} - -static void extendFileUtils(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "FileUtils"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"getStringFromFile"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_FileUtils_getStringFromFile ); - lua_rawset(tolua_S,-3); - } -} - -static void extendUserDefault(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "UserDefault"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"getInstance"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_UserDefault_getInstance ); - lua_rawset(tolua_S,-3); - } -} - -static void extendSpriteBatchNode(lua_State* tolua_S) -{ - lua_pushstring(tolua_S, "SpriteBatchNode"); - lua_rawget(tolua_S, LUA_REGISTRYINDEX); - if (lua_istable(tolua_S,-1)) - { - lua_pushstring(tolua_S,"getDescendants"); - lua_pushcfunction(tolua_S,tolua_cocos2dx_SpriteBatchNode_getDescendants ); - lua_rawset(tolua_S,-3); - } -} - - -int register_all_cocos2dx_manual(lua_State* tolua_S) -{ - if (NULL == tolua_S) - return 0; - - extendNode(tolua_S); - extendLayer(tolua_S); - extendMenuItem(tolua_S); - extendMenuItemImage(tolua_S); - extendMenuItemLabel(tolua_S); - extendMenuItemFont(tolua_S); - extendMenuItemSprite(tolua_S); - extendMenuItemToggle(tolua_S); - extendMenu(tolua_S); - extendScheduler(tolua_S); - extendSequence(tolua_S); - extendCallFunc(tolua_S); - extendSpawn(tolua_S); - extendCardinalSplineBy(tolua_S); - extendCatmullRomBy(tolua_S); - extendCatmullRomTo(tolua_S); - extendBezierBy(tolua_S); - extendBezierTo(tolua_S); - extendDrawNode(tolua_S); - extendSprite(tolua_S); - extendLayerColor(tolua_S); - extendLayerMultiplex(tolua_S); - extendParticleSystem(tolua_S); - extendCamera(tolua_S); - extendFileUtils(tolua_S); - extendUserDefault(tolua_S); - extendGLProgram(tolua_S); - extendTexture2D(tolua_S); - extendSpriteBatchNode(tolua_S); - return 0; -} \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id new file mode 100644 index 0000000000..c59adc5e90 --- /dev/null +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -0,0 +1 @@ +6f20ef3b233b2dffcfa11fe289879cfc5ee35d51 \ No newline at end of file diff --git a/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua b/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua index 0a179dce6b..261dd70730 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua @@ -1233,7 +1233,8 @@ local function ExtensionsMainLayer() item:setPosition(s.width / 2, s.height - i * LINE_SPACE) menu:addChild(item, kItemTagBasic + i) if ((i == ExtensionTestEnum.TEST_WEBSOCKET + 1) and (false == bSupportWebSocket)) - or ((i == ExtensionTestEnum.TEST_EDITBOX + 1) and (false == bSupportEdit)) then + or ((i == ExtensionTestEnum.TEST_EDITBOX + 1) and (false == bSupportEdit)) + or (i == ExtensionTestEnum.TEST_NOTIFICATIONCENTER + 1)then item:setEnabled(false) end end diff --git a/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua b/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua index 25588d87eb..3fe30f0a7f 100644 --- a/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/MenuTest/MenuTest.lua @@ -546,15 +546,15 @@ local function BugsTest() local ret = cc.Layer:create() local function issue1410MenuCallback(tag, pSender) local menu = tolua.cast(pSender:getParent(), "Menu") - menu:setTouchEnabled(false) - menu:setTouchEnabled(true) + menu:setEnabled(false) + menu:setEnabled(true) cclog("NO CRASHES") end local function issue1410v2MenuCallback(tag, pSender) local menu = tolua.cast(pSender:getParent(), "Menu") - menu:setTouchEnabled(true) - menu:setTouchEnabled(false) + menu:setEnabled(true) + menu:setEnabled(false) cclog("NO CRASHES. AND MENU SHOULD STOP WORKING") end diff --git a/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua b/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua index beab70922e..b86eb3a1d3 100644 --- a/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/UserDefaultTest/UserDefaultTest.lua @@ -75,6 +75,7 @@ function UserDefaultTestMain() local label = cc.LabelTTF:create("UserDefault test see log", "Arial", 28) ret:addChild(label, 0) label:setPosition( cc.p(s.width/2, s.height-50) ) + ret:addChild(CreateBackMenuItem()) doTest() return ret end