Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36242,63 +36242,6 @@ int lua_cocos2dx_EventDispatcher_setPriority(lua_State* tolua_S)

return 0;
}
int lua_cocos2dx_EventDispatcher_addCustomEventListener(lua_State* tolua_S)
{
int argc = 0;
cocos2d::EventDispatcher* cobj = nullptr;
bool ok = true;

#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.EventDispatcher",0,&tolua_err)) goto tolua_lerror;
#endif

cobj = (cocos2d::EventDispatcher*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'", nullptr);
return 0;
}
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 2)
{
std::string arg0;
std::function<void (cocos2d::EventCustom *)> arg1;

ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.EventDispatcher:addCustomEventListener");

do {
// Lambda binding for lua is not supported.
assert(false);
} while(0)
;
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'", nullptr);
return 0;
}
cocos2d::EventListenerCustom* ret = cobj->addCustomEventListener(arg0, arg1);
object_to_luaval<cocos2d::EventListenerCustom>(tolua_S, "cc.EventListenerCustom",(cocos2d::EventListenerCustom*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.EventDispatcher:addCustomEventListener",argc, 2);
return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'.",&tolua_err);
#endif

return 0;
}
int lua_cocos2dx_EventDispatcher_dispatchEvent(lua_State* tolua_S)
{
int argc = 0;
Expand Down Expand Up @@ -36652,7 +36595,6 @@ int lua_register_cocos2dx_EventDispatcher(lua_State* tolua_S)
tolua_function(tolua_S,"resumeEventListenersForTarget",lua_cocos2dx_EventDispatcher_resumeEventListenersForTarget);
tolua_function(tolua_S,"removeEventListenersForTarget",lua_cocos2dx_EventDispatcher_removeEventListenersForTarget);
tolua_function(tolua_S,"setPriority",lua_cocos2dx_EventDispatcher_setPriority);
tolua_function(tolua_S,"addCustomEventListener",lua_cocos2dx_EventDispatcher_addCustomEventListener);
tolua_function(tolua_S,"dispatchEvent",lua_cocos2dx_EventDispatcher_dispatchEvent);
tolua_function(tolua_S,"hasEventListener",lua_cocos2dx_EventDispatcher_hasEventListener);
tolua_function(tolua_S,"removeAllEventListeners",lua_cocos2dx_EventDispatcher_removeAllEventListeners);
Expand Down
123 changes: 123 additions & 0 deletions cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,123 @@
#include "platform/CCGLView.h"
#include "renderer/CCTextureCache.h"

struct LuaCustomEventListener {
LuaCustomEventListener(lua_State* state, int index): L(state), ref(LUA_NOREF)
{
luaL_checktype(L, index, LUA_TFUNCTION);
lua_pushvalue(L, index);
ref = luaL_ref(L, LUA_REGISTRYINDEX);
}
~LuaCustomEventListener()
{
unref();
}

void operator()(cocos2d::EventCustom* e)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);

object_to_luaval<cocos2d::EventCustom>(L, "cc.EventCustom", e);
lua_call(L, 1, 0);
}

LuaCustomEventListener(const LuaCustomEventListener& other): L(nullptr), ref(LUA_NOREF)
{
*this = other;
}
LuaCustomEventListener& operator=(const LuaCustomEventListener& rhs)
{
if (this != &rhs)
{
unref();
L = rhs.L;
lua_rawgeti(L, LUA_REGISTRYINDEX, rhs.ref);
ref = luaL_ref(L, LUA_REGISTRYINDEX);
}
return *this;
}

LuaCustomEventListener(LuaCustomEventListener&& other): L(nullptr), ref(LUA_NOREF)
{
*this = std::move(other);
}

LuaCustomEventListener& operator=(LuaCustomEventListener&& rhs)
{
if (this != &rhs)
{
unref();

L = rhs.L;
ref = rhs.ref;

rhs.L = nullptr;
rhs.ref = LUA_NOREF;
}
return *this;
}
private:
inline void unref() {
if (L && ref != LUA_NOREF && ref != LUA_REFNIL)
luaL_unref(L, LUA_REGISTRYINDEX, ref);
}

lua_State* L;
int ref;
};
int lua_cocos2dx_EventDispatcher_addCustomEventListener(lua_State* tolua_S)
{
int argc = 0;
cocos2d::EventDispatcher* cobj = nullptr;
bool ok = true;

#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.EventDispatcher",0,&tolua_err)) goto tolua_lerror;
#endif

cobj = (cocos2d::EventDispatcher*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'", nullptr);
return 0;
}
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 2)
{
std::string arg0;

ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.EventDispatcher:addCustomEventListener");
auto callback = LuaCustomEventListener(tolua_S, 3);

if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'", nullptr);
return 0;
}
cocos2d::EventListenerCustom* ret = cobj->addCustomEventListener(arg0, std::function<void (cocos2d::EventCustom *)>(std::move(callback)));
object_to_luaval<cocos2d::EventListenerCustom>(tolua_S, "cc.EventListenerCustom",(cocos2d::EventListenerCustom*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.EventDispatcher:addCustomEventListener",argc, 2);
return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_EventDispatcher_addCustomEventListener'.",&tolua_err);
#endif

return 0;
}

static int tolua_cocos2d_MenuItemImage_create(lua_State* tolua_S)
{
if (nullptr == tolua_S)
Expand Down Expand Up @@ -8126,6 +8243,12 @@ int register_all_cocos2dx_module_manual(lua_State* tolua_S)
tolua_function(tolua_S, "findChildren", tolua_cocos2d_utils_findChildren);
tolua_function(tolua_S, "findChild", tolua_cocos2d_utils_findChild);
tolua_endmodule(tolua_S);

tolua_module(tolua_S, "EventDispatcher", 0);
tolua_beginmodule(tolua_S,"EventDispatcher");
tolua_function(tolua_S,"addCustomEventListener",lua_cocos2dx_EventDispatcher_addCustomEventListener);
tolua_endmodule(tolua_S);

tolua_endmodule(tolua_S);

return 0;
Expand Down
Loading