Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: cc.ComponentLua #20721

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
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
17 changes: 5 additions & 12 deletions cocos/scripting/lua-bindings/manual/CCComponentLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,11 @@ void ComponentLua::storeLuaTable()
lua_rawset(l, -3); // stack: table_return_from_lua table_of_component
lua_pop(l, 1); // stack: table_return_from_lua

// add table's elements to userdata's metatable
object_to_luaval<cocos2d::ComponentLua>(l, "cc.ComponentLua", this); // stack: table_return_from_lua userdata
lua_getmetatable(l, -1); // stack: table_return_from_lua userdata mt
lua_remove(l, -2); // stack: table_return_from_lua mt
lua_pushnil(l); // stack: table_return_from_lua mt nil
while (lua_next(l, -3)) // stack: table_return_from_lua mt key value
{
lua_pushvalue(l, -2); // stack: table_return_from_lua mt key value key
lua_insert(l, -2); // stack: table_return_from_lua mt key key value
lua_rawset(l, -4); // stack: table_return_from_lua mt key
}
lua_pop(l, 2);
// set table_return_from_lua as the new environment for this
object_to_luaval<cocos2d::ComponentLua>(l, "cc.ComponentLua", this); // stack: table_return_from_lua/this
lua_pushvalue(l, -2); // stack: table_return_from_lua/this/table_return_from_lua
lua_setfenv(l, -2); // stack: table_return_from_lua/this
lua_pop(l, 1); // stack: table_return_from_lua
}

void ComponentLua::removeLuaTable()
Expand Down