From: John L. <jr...@us...> - 2007-03-21 05:20:00
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv23802/modules/wxlua/src Modified Files: wxlbind.cpp Log Message: Put proof of concept code for pushing the class constructors as tables with __call metatable or cfunctions with a __index metatable to allow static functions and enums that are class members to be a little nicer in the bindings. Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** wxlbind.cpp 19 Mar 2007 21:56:11 -0000 1.56 --- wxlbind.cpp 21 Mar 2007 05:19:56 -0000 1.57 *************** *** 541,545 **** // prevent changes from lua scripts ! wxlState.tsettagmethod(m_wxLuaTable, "__newindex", wxLua_lua_tableErrorHandler); // FIXME allow this? } else --- 541,545 ---- // prevent changes from lua scripts ! //wxlState.tsettagmethod(m_wxLuaTable, "__newindex", wxLua_lua_tableErrorHandler); // FIXME allow this? } else *************** *** 623,629 **** --- 623,692 ---- if ((pMethod->type == LuaConstructor) || (pMethod->type == LuaGlobal)) { + #if 0 // C++ class constructors are tables and use the __call metatable to make them "functions" + // push name of nested table and create the table + lua_pushstring(L, pMethod->name); + lua_newtable(L); + + // add the items to the table as t[first pushed] = second pushed + lua_pushstring(L, "key"); + lua_pushstring(L, "value"); + lua_rawset(L, -3); // same as lua_setfield(L, -2, "key") + + lua_pushstring(L, "new"); + lua_pushcfunction(L, pMethod->func); + lua_rawset(L, -3); + + + // Create the metatable for this table + //luaL_newmetatable(L, pMethod->func); // we don't need to register it + lua_newtable(L); + + lua_pushstring(L, "__call"); + lua_pushcfunction(L, pMethod->func); + lua_rawset(L, -3); + + //lua_pushstring(L, "__metatable"); + //lua_pushstring(L, "Metatable is not accessible"); + //lua_rawset(L, -3); + + lua_setmetatable(L, -2); + + // add table to the binding table t[pMethod->name] = { this table } + lua_rawset(L, -3); // same as lua_settable(L, tableOffset); + + #elif 0 // C++ constructors are cfunctions, use metatable for access to items. + lua_pushstring(L, pMethod->name); + lua_pushcfunction(L, pMethod->func); + + // Create the metatable for this cfunction + //luaL_newmetatable(L, pMethod->func); // we don't need to register it + lua_newtable(L); + + // create the t[__index] = { table } + lua_pushstring(L, "__index"); + lua_newtable(L); + + // add the items to the table as t[first pushed] = second pushed + lua_pushstring(L, "key"); + lua_pushstring(L, "value"); + lua_rawset(L, -3); // same as lua_setfield(L, -2, "key") + + //set the table + lua_rawset(L, -3); + + //lua_pushstring(L, "__metatable"); + //lua_pushstring(L, "Metatable is not accessible"); + //lua_rawset(L, -3); + + lua_setmetatable(L, -2); + + lua_rawset(L, tableOffset); + + #else // C++ class constructors are cfunctions only + lua_pushstring(L, pMethod->name); lua_pushcfunction(L, pMethod->func); lua_rawset(L, tableOffset); + #endif } } |