From: John L. <jr...@us...> - 2007-02-26 01:57:26
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv32575/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp Log Message: Change WXLUACLASS to keep a pointer to the base class's WXLUACLASS not it's tag for faster lookup. cleanup of the headers, more comments Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** wxlstate.cpp 22 Feb 2007 00:01:36 -0000 1.87 --- wxlstate.cpp 26 Feb 2007 01:57:06 -0000 1.88 *************** *** 420,424 **** { lua_pushstring(L, method); ! lua_pushlightuserdata(L, pClass); lua_pushcclosure(L, func, 1); } --- 420,424 ---- { lua_pushstring(L, method); ! lua_pushlightuserdata(L, pClass); lua_pushcclosure(L, func, 1); } *************** *** 1146,1151 **** // register handlers to send events ! RegisterFunction(wxLua_lua_printFunction, wxT("print")); ! //RegisterFunction(wxLua_lua_tracebackFunction, wxT("debug.traceback")); //wxT("_TRACEBACK")); // now register bindings --- 1146,1151 ---- // register handlers to send events ! RegisterFunction(wxLua_lua_printFunction, "print"); ! //RegisterFunction(wxLua_lua_tracebackFunction, "debug.traceback"); //wxT("_TRACEBACK")); // now register bindings *************** *** 1189,1194 **** // register handlers to send events ! RegisterFunction(wxLua_lua_printFunction, wxT("print")); ! //RegisterFunction(wxLua_lua_tracebackFunction, wxT("debug.traceback")); //wxT("_TRACEBACK")); // now register bindings --- 1189,1194 ---- // register handlers to send events ! RegisterFunction(wxLua_lua_printFunction, "print"); ! //RegisterFunction(wxLua_lua_tracebackFunction, "debug.traceback"); //wxT("_TRACEBACK")); // now register bindings *************** *** 1684,1690 **** { WXLUACLASS* pLuaClass = pClass + i; ! pLuaClass->baseclass_tag = -1; ! if (pLuaClass->baseclass) { wxLuaBindingList::Node* basenode; --- 1684,1690 ---- { WXLUACLASS* pLuaClass = pClass + i; ! // pLuaClass->baseclass = NULL; FIXME ! if (pLuaClass->baseclassName) { wxLuaBindingList::Node* basenode; *************** *** 1694,1698 **** // found base class in binding? ! if (basebinding->SetBaseClassTag(pLuaClass)) break; } --- 1694,1698 ---- // found base class in binding? ! if (basebinding->SetBaseClass(pLuaClass)) break; } *************** *** 1776,1782 **** { wxCHECK_MSG(GetRefData() != NULL, NULL, wxT("Invalid wxLuaState")); const WXLUACLASS *pLuaClass = GetLuaClass(iClassTag); ! if (pLuaClass && (pLuaClass->baseclass_tag != -1)) ! return GetLuaClass(pLuaClass->baseclass_tag); return NULL; --- 1776,1783 ---- { wxCHECK_MSG(GetRefData() != NULL, NULL, wxT("Invalid wxLuaState")); + const WXLUACLASS *pLuaClass = GetLuaClass(iClassTag); ! if (pLuaClass) ! return pLuaClass->baseclass; return NULL; *************** *** 1789,1803 **** const WXLUACLASS *pLuaClass = GetLuaClass(iClassTag); ! if (pLuaClass && (pLuaClass->baseclass_tag != -1)) ! return IsDerivedClass(pLuaClass->baseclass_tag, iBaseClassTag); return false; } ! const WXLUAEVENT* wxLuaState::GetLuaEvent(wxEvent *pEvent) const { ! wxCHECK_MSG(Ok() && pEvent, NULL, wxT("Invalid wxLuaState or wxEvent")); WXLUAEVENT eventItem; ! int eventType = pEvent->GetEventType(); eventItem.eventType = &eventType; --- 1790,1804 ---- const WXLUACLASS *pLuaClass = GetLuaClass(iClassTag); ! if (pLuaClass && pLuaClass->baseclass) ! return IsDerivedClass(*pLuaClass->baseclass->class_tag, iBaseClassTag); return false; } ! const WXLUAEVENT* wxLuaState::GetLuaEvent(wxEventType eventType_) const { ! wxCHECK_MSG(Ok(), NULL, wxT("Invalid wxLuaState")); WXLUAEVENT eventItem; ! int eventType = eventType_; eventItem.eventType = &eventType; *************** *** 2351,2355 **** wxLua_lua_terror(L, wx2lua(msg)); ! return wxEmptyString; } bool wxLuaState::GetBooleanType(int stack_idx) --- 2352,2356 ---- wxLua_lua_terror(L, wx2lua(msg)); ! return wxEmptyString; } bool wxLuaState::GetBooleanType(int stack_idx) *************** *** 2448,2463 **** } ! WXLUAMETHOD* wxLuaState::GetLuaMethod(const WXLUACLASS *pClass, const char *cpIndex, bool &isProperty) { ! ! int iMethod, method_count = pClass->num_methods; // find a method in the class, recurse through classes from which this class is derived. ! for (iMethod = 0; iMethod < method_count; ++iMethod) { ! WXLUAMETHOD *pMethod = pClass->methods + iMethod; if (((pMethod->type == LuaMethod) || (pMethod->type == LuaGetProp)) && (strcmp(pMethod->name, cpIndex) == 0)) { - isProperty = (pMethod->type == LuaGetProp); return pMethod; } --- 2449,2462 ---- } ! WXLUAMETHOD* wxLuaState::GetLuaMethod(const WXLUACLASS *pClass, const char *cpIndex) { ! int i_method, method_count = pClass->num_methods; // find a method in the class, recurse through classes from which this class is derived. ! for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *pMethod = pClass->methods + i_method; if (((pMethod->type == LuaMethod) || (pMethod->type == LuaGetProp)) && (strcmp(pMethod->name, cpIndex) == 0)) { return pMethod; } *************** *** 2469,2485 **** const WXLUACLASS* pBaseClass = GetBaseLuaClass(*pClass->class_tag); if (pBaseClass) ! return GetLuaMethod(pBaseClass, cpIndex, isProperty); return NULL; } ! WXLUAMETHOD* wxLuaState::GetLuaProperty(const WXLUACLASS *pClass, const char *cpIndex, bool isSet) { ! int iMethod, method_count = pClass->num_methods; // find a method in the class, recurse through classes from which this class is derived. ! for (iMethod = 0; iMethod < method_count; ++iMethod) { ! WXLUAMETHOD *pMethod = pClass->methods + iMethod; ! if (isSet) { if ((pMethod->type == LuaSetProp) && (strcmp(pMethod->name, cpIndex) == 0)) --- 2468,2486 ---- const WXLUACLASS* pBaseClass = GetBaseLuaClass(*pClass->class_tag); if (pBaseClass) ! return GetLuaMethod(pBaseClass, cpIndex); return NULL; } ! WXLUAMETHOD* wxLuaState::GetLuaProperty(const WXLUACLASS *pClass, const char *cpIndex, bool isLuaSetProp) { ! wxCHECK_MSG(pClass, NULL, wxT("Invalid WXLUACLASS in wxLuaState::GetLuaProperty")); ! ! int i_method, method_count = pClass->num_methods; // find a method in the class, recurse through classes from which this class is derived. ! for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *pMethod = pClass->methods + i_method; ! if (isLuaSetProp) { if ((pMethod->type == LuaSetProp) && (strcmp(pMethod->name, cpIndex) == 0)) *************** *** 2498,2502 **** const WXLUACLASS* pBaseClass = GetBaseLuaClass(*pClass->class_tag); if (pBaseClass) ! return GetLuaProperty(pBaseClass, cpIndex, isSet); return NULL; --- 2499,2503 ---- const WXLUACLASS* pBaseClass = GetBaseLuaClass(*pClass->class_tag); if (pBaseClass) ! return GetLuaProperty(pBaseClass, cpIndex, isLuaSetProp); return NULL; *************** *** 2521,2525 **** if ((pLuaObject != NULL) && pLuaObject->GetObject()) { ! wxCHECK_MSG(pLuaObject->GetwxLuaState() == *this, false, wxT("wxLuaState HasDerivedMethod out of sync")); return true; } --- 2522,2526 ---- if ((pLuaObject != NULL) && pLuaObject->GetObject()) { ! wxCHECK_MSG(pLuaObject->GetwxLuaState() == *this, false, wxT("wxLuaState for HasDerivedMethod out of sync")); return true; } *************** *** 3265,3269 **** luapath += path + wxT(';'); ! lua_PushString(wx2lua(luapath)); lua_SetGlobal(LUA_PATH); } --- 3266,3270 ---- luapath += path + wxT(';'); ! lua_PushString(luapath); lua_SetGlobal(LUA_PATH); } *************** *** 3581,3586 **** DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_ERROR) DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUG_HOOK) ! DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_INIT) ! DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUGGERATTACHED) wxLuaEvent::wxLuaEvent(wxEventType commandType, wxWindowID id, const wxLuaState& wxlState) --- 3582,3587 ---- DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_ERROR) DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUG_HOOK) ! //DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_INIT) ! //DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUGGERATTACHED) wxLuaEvent::wxLuaEvent(wxEventType commandType, wxWindowID id, const wxLuaState& wxlState) Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** wxlbind.cpp 7 Feb 2007 04:56:24 -0000 1.50 --- wxlbind.cpp 26 Feb 2007 01:57:06 -0000 1.51 *************** *** 21,24 **** --- 21,25 ---- #include "wx/listimpl.cpp" + WX_DEFINE_LIST(wxLuaBindingList); // Binding tags are generated as positive tag id automatically when bound *************** *** 41,46 **** int s_wxluaarg_LuaFunction = -9; - WX_DEFINE_LIST(wxLuaBindingList); - //----------------------------------------------------------------------------- // wxLuaFunction --- 42,45 ---- *************** *** 82,86 **** (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { ! wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1); return pFunction->CallMethod(L); } --- 81,85 ---- (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { ! wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1, false); return pFunction->CallMethod(L); } *************** *** 367,375 **** if (!fFound) { ! bool propertyFlag; ! WXLUAMETHOD *pMethod = wxlState.GetLuaMethod(pClass, cpIndex, propertyFlag); if (pMethod != NULL) { ! if (propertyFlag) { lua_remove(L, 2); --- 366,373 ---- if (!fFound) { ! WXLUAMETHOD *pMethod = wxlState.GetLuaMethod(pClass, cpIndex); if (pMethod != NULL) { ! if (pMethod->type == LuaGetProp) { lua_remove(L, 2); *************** *** 380,389 **** { wxLuaFunction *pFunction = new wxLuaFunction(pMethod, pClass, pObject); ! if (pFunction != NULL) ! { ! wxlState.tpushusertag(pFunction, wxlState.GetwxLuaFunctionTag()); ! result = 1; ! fFound = true; ! } } } --- 378,384 ---- { wxLuaFunction *pFunction = new wxLuaFunction(pMethod, pClass, pObject); ! wxlState.tpushusertag(pFunction, wxlState.GetwxLuaFunctionTag()); ! result = 1; ! fFound = true; } } *************** *** 420,424 **** const char *cpIndex = lua_tostring(L, 2); ! //wxPrintf(wxT("wxLua_lua_setTableFunc '%s'\n"), lua2wx(cpIndex).c_str()); if ((pClass != NULL) && lua_isuserdata(L, 1) && --- 415,419 ---- const char *cpIndex = lua_tostring(L, 2); ! wxPrintf(wxT("wxLua_lua_setTableFunc '%s'\n"), lua2wx(cpIndex).c_str()); if ((pClass != NULL) && lua_isuserdata(L, 1) && *************** *** 426,429 **** --- 421,425 ---- (wxlState.ttag(1) == *pClass->class_tag)) { + // See if there is a LuaSetProp in the WXLUACLASS's WXLUAMETHODs WXLUAMETHOD *pMethod = wxlState.GetLuaProperty(pClass, cpIndex, true); if (pMethod != NULL) *************** *** 447,472 **** { pHashTable = new wxLuaStringToLongHashMap; ! if (pHashTable != NULL) ! { ! wxlState.GetLuaStateData()->m_pDerivedList[(long) pObject] = (long)pHashTable; ! fCreated = true; ! } } ! if (pHashTable != NULL) { ! wxString index = lua2wx(cpIndex); ! if (!fCreated) { ! wxLuaStringToLongHashMap::iterator it = pHashTable->find(index); ! if (it != pHashTable->end()) ! { ! wxLuaObject *pObject = (wxLuaObject *)it->second; ! if (pObject != NULL) ! delete pObject; ! } } - (*pHashTable)[index] = (long)new wxLuaObject(wxlState, 3); } } } --- 443,463 ---- { pHashTable = new wxLuaStringToLongHashMap; ! wxlState.GetLuaStateData()->m_pDerivedList[(long) pObject] = (long)pHashTable; ! fCreated = true; } ! wxString index = lua2wx(cpIndex); ! if (!fCreated) { ! wxLuaStringToLongHashMap::iterator it = pHashTable->find(index); ! if (it != pHashTable->end()) { ! wxLuaObject *pObject = (wxLuaObject *)it->second; ! if (pObject != NULL) ! delete pObject; } } + + (*pHashTable)[index] = (long)new wxLuaObject(wxlState, 3); } } *************** *** 515,523 **** { wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); int luaTable = RegisterFunctions(wxlState, registerTypes); lua_State *L = wxlState.GetLuaState(); ! // create a global for the namespace if it doesn't already exist lua_getglobal(L, wx2lua(m_nameSpace)); --- 506,515 ---- { wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); + int luaTable = RegisterFunctions(wxlState, registerTypes); lua_State *L = wxlState.GetLuaState(); ! // create a global table for the namespace if it doesn't already exist lua_getglobal(L, wx2lua(m_nameSpace)); *************** *** 553,558 **** int tableOffset = 0; ! // create a global for the namespace if it doesn't already exist lua_getglobal(L, wx2lua(m_nameSpace)); if (!lua_istable(L, -1)) { --- 545,551 ---- int tableOffset = 0; ! // create a global table for the namespace if it doesn't already exist lua_getglobal(L, wx2lua(m_nameSpace)); + if (!lua_istable(L, -1)) { *************** *** 607,611 **** void LUACALL wxLuaBinding::RegisterGeneratedClasses(const wxLuaState& wxlState_, int tableOffset, bool registerTypes) { ! // Replace the metatable functions for the functions we push into lua static const luaL_reg s_funcTable[] = { --- 600,604 ---- void LUACALL wxLuaBinding::RegisterGeneratedClasses(const wxLuaState& wxlState_, int tableOffset, bool registerTypes) { ! // Replace the metatable functions for the classes we push into lua static const luaL_reg s_funcTable[] = { *************** *** 626,648 **** // install the classes, functions and methods, creating new tags ! // if this is the first time we're registering them, else assume ! // they are in numerical order. ! for (size_t iClass = 0; iClass < m_classCount; ++iClass, ! iTag = (registerTypes ? wxlState.tnewtag() : iTag + 1)) { ! WXLUACLASS *pClass = m_classList + iClass; ! *pClass->class_tag = iTag; // set the metatable functions for the classes ! for (size_t iFunction = 0; iFunction < s_funcCount; iFunction++) { ! wxlState.tsettagmethod(iTag, s_funcTable[iFunction].name, s_funcTable[iFunction].func, (void *) pClass); } // install public functions like constructors or global functions ! int iMethod, method_count = pClass->num_methods; ! for (iMethod = 0; iMethod < method_count; ++iMethod) { ! WXLUAMETHOD *pMethod = pClass->methods + iMethod; if ((pMethod->type == LuaConstructor) || (pMethod->type == LuaGlobal)) { --- 619,647 ---- // install the classes, functions and methods, creating new tags ! // if this is the first time we're registering them ! for (size_t i_class = 0; i_class < m_classCount; ++i_class) { ! WXLUACLASS *pClass = m_classList + i_class; ! ! // Create a new tag if registering types, else use tag already set ! if (registerTypes) ! { ! iTag = wxlState.tnewtag(); ! *pClass->class_tag = iTag; ! } ! else ! iTag = *pClass->class_tag; // set the metatable functions for the classes ! for (size_t i_func = 0; i_func < s_funcCount; ++i_func) { ! wxlState.tsettagmethod(iTag, s_funcTable[i_func].name, s_funcTable[i_func].func, (void *)pClass); } // install public functions like constructors or global functions ! int i_method, method_count = pClass->num_methods; ! for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *pMethod = pClass->methods + i_method; if ((pMethod->type == LuaConstructor) || (pMethod->type == LuaGlobal)) { *************** *** 657,663 **** // register all the builtin functions, global C style functions ! for (size_t iFunction = 0; iFunction < m_functionCount; ++iFunction) { ! WXLUAMETHOD *pMethod = m_functionList + iFunction; lua_pushstring(L, pMethod->name); lua_pushcfunction(L, pMethod->func); --- 656,662 ---- // register all the builtin functions, global C style functions ! for (size_t i_func = 0; i_func < m_functionCount; ++i_func) { ! WXLUAMETHOD *pMethod = m_functionList + i_func; lua_pushstring(L, pMethod->name); lua_pushcfunction(L, pMethod->func); *************** *** 674,680 **** // install the numerical definitions ! for (size_t iDefine = 0; iDefine < m_defineCount; ++iDefine) { ! WXLUADEFINE *pDefine = m_defineList + iDefine; lua_pushstring(L, pDefine->name); lua_pushnumber(L, pDefine->value); --- 673,679 ---- // install the numerical definitions ! for (size_t i_define = 0; i_define < m_defineCount; ++i_define) { ! WXLUADEFINE *pDefine = m_defineList + i_define; lua_pushstring(L, pDefine->name); lua_pushnumber(L, pDefine->value); *************** *** 683,689 **** // install the strings ! for (size_t iString = 0; iString < m_stringCount; ++iString) { ! WXLUASTRING *pString = m_stringList + iString; lua_pushstring(L, pString->name); lua_pushstring(L, wx2lua(pString->value)); --- 682,688 ---- // install the strings ! for (size_t i_string = 0; i_string < m_stringCount; ++i_string) { ! WXLUASTRING *pString = m_stringList + i_string; lua_pushstring(L, pString->name); lua_pushstring(L, wx2lua(pString->value)); *************** *** 692,703 **** // install the objects and pointers ! for (size_t iObject = 0; iObject < m_objectCount; ++iObject) { ! WXLUAOBJECT *pObject = m_objectList + iObject; ! lua_pushstring(L, pObject->objName); if (pObject->objPtr != 0) ! wxlState.tpushusertag(pObject->objPtr, *pObject->objClassTag); else ! wxlState.tpushusertag(*pObject->pObjPtr, *pObject->objClassTag); lua_rawset(L, tableOffset); --- 691,703 ---- // install the objects and pointers ! for (size_t i_object = 0; i_object < m_objectCount; ++i_object) { ! WXLUAOBJECT *pObject = m_objectList + i_object; ! lua_pushstring(L, pObject->name); ! if (pObject->objPtr != 0) ! wxlState.tpushusertag(pObject->objPtr, *pObject->class_tag); else ! wxlState.tpushusertag(*pObject->pObjPtr, *pObject->class_tag); lua_rawset(L, tableOffset); *************** *** 705,712 **** // register all the wxevent types ! for (size_t iEvent = 0; iEvent < m_eventCount; ++iEvent) { ! WXLUAEVENT *pEvent = m_eventList + iEvent; ! lua_pushstring(L, pEvent->eventName); lua_pushnumber(L, *pEvent->eventType); lua_rawset(L, tableOffset); --- 705,712 ---- // register all the wxevent types ! for (size_t i_event = 0; i_event < m_eventCount; ++i_event) { ! WXLUAEVENT *pEvent = m_eventList + i_event; ! lua_pushstring(L, pEvent->name); lua_pushnumber(L, *pEvent->eventType); lua_rawset(L, tableOffset); *************** *** 717,733 **** } ! bool wxLuaBinding::SetBaseClassTag(WXLUACLASS *pClass) { ! if (!pClass->baseclass || !m_classList) return false; ! // install the classes, functions and methods ! for (size_t i = 0; i < m_classCount; ++i) { ! WXLUACLASS* baseClass = m_classList + i; ! if (strcmp(baseClass->name, pClass->baseclass) == 0) { ! pClass->baseclass_tag = *baseClass->class_tag; return true; } --- 717,732 ---- } ! bool wxLuaBinding::SetBaseClass(WXLUACLASS *pClass) { ! if (!pClass->baseclassName) // check if there is a baseclassName at all return false; ! for (size_t n = 0; n < m_classCount; ++n) { ! WXLUACLASS* baseClass = m_classList + n; // potential base class ! if (strcmp(baseClass->name, pClass->baseclassName) == 0) { ! pClass->baseclass = baseClass; return true; } *************** *** 739,748 **** wxString wxLuaBinding::GetEventTypeName(wxEventType e_type) { ! size_t n = 0, count = GetLuaEventCount(); ! for (n = 0; n < count; n++) { ! WXLUAEVENT *pEvent = &m_eventList[n]; if (*pEvent->eventType == (int)e_type) ! return lua2wx(pEvent->eventName); } --- 738,747 ---- wxString wxLuaBinding::GetEventTypeName(wxEventType e_type) { ! for (size_t n = 0; n < m_eventCount; ++n) { ! WXLUAEVENT *pEvent = m_eventList + n; ! if (*pEvent->eventType == (int)e_type) ! return lua2wx(pEvent->name); } Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** wxlcallb.cpp 21 Jan 2007 23:13:07 -0000 1.24 --- wxlcallb.cpp 26 Feb 2007 01:57:06 -0000 1.25 *************** *** 117,123 **** int eventClassTag = wxlState.GetwxEventTag(); // get the s_wxluatag_wxEvent ! const WXLUAEVENT *pLuaEvent = wxlState.GetLuaEvent(pEvent); if (pLuaEvent) ! eventClassTag = *pLuaEvent->eventClassTag; lua_checkstack(wxlState.GetLuaState(), LUA_MINSTACK); --- 117,123 ---- int eventClassTag = wxlState.GetwxEventTag(); // get the s_wxluatag_wxEvent ! const WXLUAEVENT *pLuaEvent = wxlState.GetLuaEvent(pEvent->GetEventType()); if (pLuaEvent) ! eventClassTag = *pLuaEvent->class_tag; lua_checkstack(wxlState.GetLuaState(), LUA_MINSTACK); *************** *** 156,159 **** --- 156,160 ---- // allocate a LUA proxy for the object const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + if (ptr != NULL) { |