From: John L. <jr...@us...> - 2007-06-28 21:53:01
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19412/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlua_bind.cpp 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: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** wxlbind.cpp 25 Jun 2007 23:04:02 -0000 1.81 --- wxlbind.cpp 28 Jun 2007 21:52:56 -0000 1.82 *************** *** 25,31 **** WX_DEFINE_LIST(wxLuaBindingList); - int LUACALL wxluabind_wxLuaBinding_index(lua_State* L); - - wxLuaArgTag s_wxluaargArray_None[1] = {0}; wxLuaBindDefine s_wxluadefineArray_None[1] = {{0, 0}}; --- 25,28 ---- *************** *** 677,697 **** PostRegister(wxlState, registerTypes, tableOffset); - // Push function to access the binding info - lua_pushstring(L, wx2lua(wxT("wxLuaBinding_") + m_bindingName)); - const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); - *ptr = this; - lua_newtable(L); - lua_pushstring(L, "__index"); - lua_pushlightuserdata(L, this); // 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); - m_bindings_registered = true; --- 674,677 ---- *************** *** 1152,1697 **** } - //----------------------------------------------------------------------------- - // 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; - } --- 1132,1133 ---- Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** wxlua_bind.cpp 16 Jun 2007 06:21:46 -0000 1.4 --- wxlua_bind.cpp 28 Jun 2007 21:52:57 -0000 1.5 *************** *** 150,153 **** --- 150,750 ---- static wxLuaBindCFunc s_wxluafunc_wxLua_function_CompileLuaScript[1] = {{ wxLua_function_CompileLuaScript, WXLUAMETHOD_CFUNCTION, 2, 2, s_wxluatagArray_wxLua_function_CompileLuaScript }}; + // %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; + } + + + static wxLuaBindCFunc s_wxluafunc_wxLua_function_GetBindings[1] = {{ wxLua_function_GetBindings, WXLUAMETHOD_CFUNCTION, 0, 0, s_wxluaargArray_None }}; + // %override wxLua_function_GetTrackedEventCallbacks // %function LuaTable GetTrackedEventCallbacks() *************** *** 311,314 **** --- 908,912 ---- { { "CompileLuaScript", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_CompileLuaScript, 1, NULL }, + { "GetBindings", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetBindings, 1, NULL }, { "GetTrackedEventCallbacks", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedEventCallbacks, 1, NULL }, { "GetTrackedTopLevelWindows", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedTopLevelWindows, 1, NULL }, |