Skip to content

Commit c17202e

Browse files
committed
Move class name to metatable[ '.classname']
So that class instance will also have access to its classname. eg. print(cc.Node['.classname']) print(node['.classname'])
1 parent 60a0156 commit c17202e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lua/tolua/tolua_map.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ static int tolua_newmetatable (lua_State* L, const char* name)
3939

4040
if (r)
4141
tolua_classevents(L); /* set meta events */
42+
43+
// metatable[".classname"] = name
44+
lua_pushliteral(L, ".classname"); // stack: metatable ".classname"
45+
lua_pushstring(L, name); // stack: metatable ".classname" name
46+
lua_rawset(L, -3); // stack: metatable
47+
4248
lua_pop(L,1);
4349
return r;
4450
}
@@ -661,10 +667,6 @@ TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name,
661667
lua_newtable(L); // stack: module lname table
662668
luaL_getmetatable(L,name); // stack: module lname table mt
663669
lua_setmetatable(L, -2); // stack: module lname table
664-
// class_table[".name"] = name
665-
lua_pushliteral(L, ".name"); // stack: module lname table ".name"
666-
lua_pushstring(L, name); // stack: module lname table ".name" name
667-
lua_rawset(L, -3); // stack: module lname table
668670
//Use a key named ".isclass" to be a flag of class_table
669671
lua_pushliteral(L, ".isclass");
670672
lua_pushboolean(L, 1);

0 commit comments

Comments
 (0)