From: John L. <jr...@us...> - 2007-06-28 21:53:00
|
Update of /cvsroot/wxlua/wxLua/bindings/wxlua In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19412/wxLua/bindings/wxlua Modified Files: override.hpp wxlua.i Log Message: Moved the bindings function for introspection in lua into the override.hpp file for the wxlua bindings. Add function wxlua.GetBindings() instead of install wxLuaBinding_XXX per binding. Index: wxlua.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxlua/wxlua.i,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** wxlua.i 17 Jun 2007 17:17:36 -0000 1.4 --- wxlua.i 28 Jun 2007 21:52:55 -0000 1.5 *************** *** 100,116 **** // --------------------------------------------------------------------------- ! // wxLuaBinding - This is NOT wrapped, but implemented in wxlbind.cpp // These items follow the structure below and ALL items are called as if they // were table members. ! // Example : wxLuaBinding_wx.GetClassCount ! // Example : print(wxLuaBinding_wx.GetClassArray[1].methods[1].name) // Note: Use only '.' and NO () to make it a function call, also check to see ! // if the item exists first (unlike the example above)! // Please see the bindings.wx.lua sample program for usage. /* ! %class wxLuaBinding_XXX - where XXX is the name of the binding // No constructor as this is read only --- 100,124 ---- // --------------------------------------------------------------------------- ! // wxLuaBinding - These are not wrapped in the standard way, but coded by hand ! // for size. // These items follow the structure below and ALL items are called as if they // were table members. ! // Example : print(wxlua.GetBindings()[1].binding.GetClassCount) ! // Example : print(wxlua.GetBindings()[1].binding.GetClassArray[1].methods[1].name) // Note: Use only '.' and NO () to make it a function call, also check to see ! // if the item exists first (unlike the example above)! ! // Also, you probably want to store the returned tables and get the values from ! // them instead of getting the whole table every time from wxlua.GetBindings()... // Please see the bindings.wx.lua sample program for usage. + // Entry point to get the objects below. + // returns an array of tables for each installed binding + // { ["name"]=GetBindingName, ["namespace"]=GetLuaNamespace, ["binding"]=wxLuaBinding* } + %function LuaTable GetBindings() + /* ! %class wxLuaBinding // No constructor as this is read only Index: override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxlua/override.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** override.hpp 16 Jun 2007 06:21:42 -0000 1.3 --- override.hpp 28 Jun 2007 21:52:55 -0000 1.4 *************** *** 158,161 **** --- 158,764 ---- %end + // =========================================================================== + // =========================================================================== + + %override wxLua_function_GetBindings + + int LUACALL wxluabind_wxLuaBinding__index(lua_State* L); + + // %function LuaTable GetBindings() + static int LUACALL wxLua_function_GetBindings(lua_State *L) + { + wxLuaState wxlState(L); + lua_newtable(L); // the table that we return + + int idx = 1; + wxLuaBindingList::compatibility_iterator node; + for (node = wxlState.GetLuaBindingList()->GetFirst(); node; node = node->GetNext(), idx++) + { + wxLuaBinding* binding = node->GetData(); + + lua_createtable(L, 3, 0); // sub table item for each binding + + lua_pushstring(L, "name"); + lua_pushstring(L, wx2lua(binding->GetBindingName())); + lua_rawset(L, -3); + + lua_pushstring(L, "namespace"); + lua_pushstring(L, wx2lua(binding->GetLuaNamespace())); + lua_rawset(L, -3); + + // Push function to access the binding info + lua_pushstring(L, "binding"); + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = binding; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, binding); // push tag to recognize table call + lua_pushcclosure(L, wxluabind_wxLuaBinding__index, 1); // push func with tag as upvalue + 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, -3); + + lua_rawseti(L, -2, idx); + } + + return 1; + } + + //----------------------------------------------------------------------------- + // wxluabind_wxLuaBindCFunc__index + //----------------------------------------------------------------------------- + int LUACALL wxluabind_wxLuaBindClass__index(lua_State* L); + + int LUACALL wxluabind_wxLuaBindCFunc__index(lua_State* L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + void **ptr = (void **)lua_touserdata(L, 1); + wxLuaBindCFunc* wxlCFunc= (wxLuaBindCFunc*)*ptr; + wxLuaBinding *wxlBinding = (wxLuaBinding *)lua_touserdata(L, lua_upvalueindex(1)); + + int idx_type = lua_type(L, 2); + + if (idx_type == LUA_TSTRING) + { + const char* idx_str = lua_tostring(L, 2); + + if (strcmp(idx_str, "func") == 0) + { + lua_pushcfunction(L, wxlCFunc->func); + return 1; + } + else if (strcmp(idx_str, "type") == 0) + { + lua_pushnumber(L, wxlCFunc->type); + return 1; + } + else if (strcmp(idx_str, "minargs") == 0) + { + lua_pushnumber(L, wxlCFunc->minargs); + return 1; + } + else if (strcmp(idx_str, "maxargs") == 0) + { + lua_pushnumber(L, wxlCFunc->maxargs); + return 1; + } + else if (strcmp(idx_str, "argtags") == 0) + { + size_t idx, count = wxlCFunc->maxargs; + lua_createtable(L, count, 0); + + // check for terminating null argtag + for (idx = 0; (idx < count) && wxlCFunc->argtags[idx]; ++idx) + { + lua_pushnumber(L, *wxlCFunc->argtags[idx]); + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "class") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlCFunc); + if (c != NULL) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = c; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + } + else if (strcmp(idx_str, "class_name") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlCFunc); + if (c != NULL) + { + lua_pushstring(L, c->name); + return 1; + } + } + } + + return 0; + } + + //----------------------------------------------------------------------------- + // wxluabind_wxLuaBindMethod__index + //----------------------------------------------------------------------------- + + int LUACALL wxluabind_wxLuaBindMethod__index(lua_State* L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + void **ptr = (void **)lua_touserdata(L, 1); + wxLuaBindMethod* wxlMethod = (wxLuaBindMethod*)*ptr; + wxLuaBinding *wxlBinding = (wxLuaBinding *)lua_touserdata(L, lua_upvalueindex(1)); + + int idx_type = lua_type(L, 2); + + if (idx_type == LUA_TSTRING) + { + const char* idx_str = lua_tostring(L, 2); + + if (strcmp(idx_str, "name") == 0) + { + lua_pushstring(L, wxlMethod->name); + return 1; + } + else if (strcmp(idx_str, "type") == 0) + { + lua_pushnumber(L, wxlMethod->type); + return 1; + } + else if (strcmp(idx_str, "funcs") == 0) + { + wxLuaBindCFunc* wxlCFunc = wxlMethod->funcs; + size_t idx, count = wxlMethod->funcs_n; + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlCFunc) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlCFunc; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindCFunc__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "funcs_n") == 0) + { + lua_pushnumber(L, wxlMethod->funcs_n); + return 1; + } + else if (strcmp(idx_str, "basemethod") == 0) + { + if (wxlMethod->basemethod) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlMethod->basemethod; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindMethod__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + + return 0; + } + else if (strcmp(idx_str, "class") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlMethod); + if (c != NULL) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = c; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + } + else if (strcmp(idx_str, "class_name") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlMethod); + if (c != NULL) + { + lua_pushstring(L, c->name); + return 1; + } + } + } + + return 0; + } + + //----------------------------------------------------------------------------- + // wxluabind_wxLuaBindClass__index + //----------------------------------------------------------------------------- + + int LUACALL wxluabind_wxLuaBindClass__index(lua_State* L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + void **ptr = (void **)lua_touserdata(L, 1); + wxLuaBindClass* wxlClass = (wxLuaBindClass*)*ptr; + wxLuaBinding *wxlBinding = (wxLuaBinding *)lua_touserdata(L, lua_upvalueindex(1)); + + int idx_type = lua_type(L, 2); + + if (idx_type == LUA_TSTRING) + { + const char* idx_str = lua_tostring(L, 2); + + if (strcmp(idx_str, "name") == 0) + { + lua_pushstring(L, wxlClass->name); + return 1; + } + else if (strcmp(idx_str, "methods") == 0) + { + if (wxlClass->methods_n > 0) + { + wxLuaBindMethod* wxlMethod = wxlClass->methods; + size_t idx, count = wxlClass->methods_n; + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlMethod) + { + // Force the baseclass methods to be found + //wxLuaBinding::GetClassMethod(wxlClass, wxlMethod->name, true); FIXME + + // Create table { wxLuaBindClass userdata } + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlMethod; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindMethod__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + lua_rawseti(L, -2, idx + 1); + } + + lua_pushstring(L, "wxLuaBindClass"); // so we know where this came from + lua_pushvalue(L, 1); + lua_rawset(L, -3); + + return 1; + } + + return 0; + } + else if (strcmp(idx_str, "methods_n") == 0) + { + lua_pushnumber(L, wxlClass->methods_n); + return 1; + } + else if (strcmp(idx_str, "classInfo") == 0) + { + if (wxlClass->classInfo) + { + const wxLuaBindClass* classInfoClass = wxlState.GetLuaClass("wxClassInfo"); + if (classInfoClass) + { + wxlState.PushUserDataType(*classInfoClass->class_tag, wxlClass->classInfo); + return 1; + } + } + + return 0; + } + else if (strcmp(idx_str, "class_tag") == 0) + { + lua_pushnumber(L, *wxlClass->class_tag); + return 1; + } + else if (strcmp(idx_str, "baseclassName") == 0) + { + lua_pushstring(L, wxlClass->baseclassName); + return 1; + } + else if (strcmp(idx_str, "baseclass") == 0) + { + if (wxlClass->baseclass) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlClass->baseclass; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + + return 0; + } + else if (strcmp(idx_str, "enums") == 0) + { + if (wxlClass->enums_n > 0) + { + wxLuaBindDefine* wxlDefine = wxlClass->enums; + size_t idx, count = wxlClass->enums_n; + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlDefine) + { + // Create table { name, value } + lua_createtable(L, 0, 2); + lua_pushstring(L, "name"); + lua_pushstring(L, wxlDefine->name); + lua_rawset(L, -3); + lua_pushstring(L, "value"); + lua_pushnumber(L, wxlDefine->value); + lua_rawset(L, -3); + + lua_rawseti(L, -2, idx + 1); + } + + lua_pushstring(L, "wxLuaBindClass"); // so we know where this came from + lua_pushvalue(L, 1); + lua_rawset(L, -3); + + return 1; + } + + return 0; + } + else if (strcmp(idx_str, "enums_n") == 0) + { + lua_pushnumber(L, wxlClass->enums_n); + return 1; + } + } + + return 0; + } + + //----------------------------------------------------------------------------- + // wxluabind_wxLuaBinding__index + //----------------------------------------------------------------------------- + + int LUACALL wxluabind_wxLuaBinding__index(lua_State* L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + void **ptr = (void **)lua_touserdata(L, 1); + wxLuaBinding* wxlBinding = (wxLuaBinding*)*ptr; + + int idx_type = lua_type(L, 2); + + if (idx_type == LUA_TSTRING) + { + const char* idx_str = lua_tostring(L, 2); + + if (strcmp(idx_str, "GetBindingName") == 0) + { + lua_pushstring(L, wx2lua(wxlBinding->GetBindingName())); + return 1; + } + else if (strcmp(idx_str, "GetLuaNamespace") == 0) + { + lua_pushstring(L, wx2lua(wxlBinding->GetLuaNamespace())); + return 1; + } + else if (strcmp(idx_str, "GetClassCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetClassCount()); + return 1; + } + else if (strcmp(idx_str, "GetDefineCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetDefineCount()); + return 1; + } + else if (strcmp(idx_str, "GetStringCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetStringCount()); + return 1; + } + else if (strcmp(idx_str, "GetEventCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetEventCount()); + return 1; + } + else if (strcmp(idx_str, "GetObjectCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetObjectCount()); + return 1; + } + else if (strcmp(idx_str, "GetFunctionCount") == 0) + { + lua_pushnumber(L, wxlBinding->GetFunctionCount()); + return 1; + } + else if (strcmp(idx_str, "GetClassArray") == 0) + { + wxLuaBindClass* wxlClass = wxlBinding->GetClassArray(); + size_t idx, count = wxlBinding->GetClassCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlClass) + { + // Create table { wxLuaBindClass userdata } + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlClass; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "GetFunctionArray") == 0) + { + wxLuaBindMethod* wxlMethod = wxlBinding->GetFunctionArray(); + size_t idx, count = wxlBinding->GetFunctionCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlMethod) + { + // Create table { wxLuaBindClass userdata } + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = wxlMethod; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindMethod__index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "GetDefineArray") == 0) + { + wxLuaBindDefine* wxlDefine = wxlBinding->GetDefineArray(); + size_t idx, count = wxlBinding->GetDefineCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlDefine) + { + // Create table { name, value } + lua_createtable(L, 0, 2); + lua_pushstring(L, "name"); + lua_pushstring(L, wxlDefine->name); + lua_rawset(L, -3); + lua_pushstring(L, "value"); + lua_pushnumber(L, wxlDefine->value); + lua_rawset(L, -3); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "GetStringArray") == 0) + { + wxLuaBindString* wxlString = wxlBinding->GetStringArray(); + size_t idx, count = wxlBinding->GetStringCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlString) + { + // Create table { name, value } + lua_createtable(L, 0, 2); + lua_pushstring(L, "name"); + lua_pushstring(L, wxlString->name); + lua_rawset(L, -3); + lua_pushstring(L, "value"); + lua_pushstring(L, wx2lua(wxlString->value)); + lua_rawset(L, -3); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "GetEventArray") == 0) + { + wxLuaBindEvent* wxlEvent = wxlBinding->GetEventArray(); + size_t idx, count = wxlBinding->GetEventCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlEvent) + { + // Create table { name, eventType, class_tag } + lua_createtable(L, 0, 3); + lua_pushstring(L, "name"); + lua_pushstring(L, wxlEvent->name); + lua_rawset(L, -3); + lua_pushstring(L, "eventType"); + lua_pushnumber(L, *wxlEvent->eventType); + lua_rawset(L, -3); + lua_pushstring(L, "class_tag"); + lua_pushnumber(L, *wxlEvent->class_tag); + lua_rawset(L, -3); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + else if (strcmp(idx_str, "GetObjectArray") == 0) + { + wxLuaBindObject* wxlObject = wxlBinding->GetObjectArray(); + size_t idx, count = wxlBinding->GetObjectCount(); + lua_createtable(L, count, 0); + + for (idx = 0; idx < count; ++idx, ++wxlObject) + { + // Create table { name, object, class_tag } + lua_createtable(L, 0, 3); + lua_pushstring(L, "name"); + lua_pushstring(L, wxlObject->name); + lua_rawset(L, -3); + + lua_pushstring(L, "object"); + if (wxlObject->objPtr != 0) + wxlState.tpushusertag(wxlObject->objPtr, *wxlObject->class_tag); + else + wxlState.tpushusertag(*wxlObject->pObjPtr, *wxlObject->class_tag); + lua_rawset(L, -3); + + lua_pushstring(L, "class_tag"); + lua_pushnumber(L, *wxlObject->class_tag); + lua_rawset(L, -3); + + lua_rawseti(L, -2, idx + 1); + } + + return 1; + } + } + + return 0; + } + + %end + + + // =========================================================================== + // =========================================================================== + %override wxLua_wxLuaObject_constructor // wxLuaObject(void *object) |