From: John L. <jr...@us...> - 2007-05-21 01:08:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv14147/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: Remove all code in dservice as it wasn't used Removed m_pDerivedList and put derived lua functions into the lua registry index A little more cleanup in the socket and editor.wx.lua code. Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** wxlstate.cpp 4 May 2007 19:04:41 -0000 1.96 --- wxlstate.cpp 21 May 2007 01:07:59 -0000 1.97 *************** *** 99,103 **** lua_pop(L, 1); /* pop result */ ! // if we know the type, add it if (lua_isuserdata(L, i) && wxlState.Ok()) { --- 99,103 ---- lua_pop(L, 1); /* pop result */ ! // if we know the type, add it if (lua_isuserdata(L, i) && wxlState.Ok()) { *************** *** 945,955 **** wxLongToLongHashMap::iterator it; - for (it = m_pDerivedList.begin(); it != m_pDerivedList.end(); ++it) - { - wxLuaStringToLongHashMap* obj = (wxLuaStringToLongHashMap*)it->second; - delete obj; - } - m_pDerivedList.clear(); - for (it = m_trackedObjects.begin(); it != m_trackedObjects.end(); ++it) { --- 945,948 ---- *************** *** 1187,1190 **** --- 1180,1189 ---- lua_rawset( L, LUA_REGISTRYINDEX ); + // Create a table for overridden functions for C++ objects + lua_pushstring( L, "__wxLuaDerivedFunctions" ); + lua_newtable(L); + // set the value + lua_rawset( L, LUA_REGISTRYINDEX ); + // create references table in registry wxlua_pushstring_wxLuaReferences(L); *************** *** 1230,1233 **** --- 1229,1238 ---- lua_rawset( L, LUA_REGISTRYINDEX ); + // Create a table for overridden functions for C++ objects + lua_pushstring( L, "__wxLuaDerivedFunctions" ); + lua_newtable(L); + // set the value + lua_rawset( L, LUA_REGISTRYINDEX ); + // create references table in registry wxlua_pushstring_wxLuaReferences(L); *************** *** 2439,2468 **** } ! bool wxLuaState::HasDerivedMethod(void *pObject, const char *method) const { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! wxLongToLongHashMap::iterator it = GetLuaStateData()->m_pDerivedList.find((long) pObject); ! if (it != GetLuaStateData()->m_pDerivedList.end()) { ! wxLuaStringToLongHashMap *pHashTable = (wxLuaStringToLongHashMap *)it->second; ! if (pHashTable != NULL) ! { ! wxLuaStringToLongHashMap::iterator its = pHashTable->find(lua2wx(method)); ! if (its != pHashTable->end()) ! { ! wxLuaObject *pLuaObject = (wxLuaObject *)its->second; ! if ((pLuaObject != NULL) && pLuaObject->GetObject()) ! { ! wxCHECK_MSG(pLuaObject->GetwxLuaState() == *this, false, wxT("wxLuaState for HasDerivedMethod out of sync")); ! return true; ! } ! } ! } } ! return false; } --- 2444,2483 ---- } ! bool wxLuaState::HasDerivedMethod(void *pObject, const char *method_name, bool push_method) const { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! wxLuaObject* wxlObj = NULL; ! lua_State* L = M_WXLSTATEDATA->m_lua_State; ! bool found = false; ! ! lua_pushstring( L, "__wxLuaDerivedFunctions" ); ! lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table ! ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil ! if (lua_istable(L, -1)) { ! // see if there is a method with the same name ! lua_pushstring( L, method_name ); ! lua_rawget(L, -2); ! if (lua_islightuserdata(L, -1)) ! wxlObj = (wxLuaObject*)lua_touserdata( L, -1 ); ! lua_pop(L, 1); // pop the method object or nil } ! lua_pop(L, 2); // pop registry table and object table or nil ! ! if (wxlObj) ! { ! if (push_method && wxlObj->GetObject()) ! found = true; ! else if (!push_method) ! found = true; ! } ! ! return found; } *************** *** 2476,2480 **** { wxLuaState wxlState((wxLuaStateRefData*)it->second, ((wxLuaStateRefData*)it->second)->m_lua_State); ! if (wxlState.HasDerivedMethod(pObject, method)) return wxlState; } --- 2491,2495 ---- { wxLuaState wxlState((wxLuaStateRefData*)it->second, ((wxLuaStateRefData*)it->second)->m_lua_State); ! if (wxlState.HasDerivedMethod(pObject, method, false)) return wxlState; } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** wxlbind.cpp 23 Mar 2007 04:27:23 -0000 1.59 --- wxlbind.cpp 21 May 2007 01:07:59 -0000 1.60 *************** *** 266,284 **** wxlState.RemoveTrackedObject((void*)key, true); // delete from m_pTrackedList ! wxLongToLongHashMap& pDerivedList = wxlState.GetLuaStateData()->m_pDerivedList; ! wxLongToLongHashMap::iterator it = pDerivedList.find(key); ! if (it != pDerivedList.end()) { ! //wxPrintf(wxT("wxlua_garbageCollect - Derived GC '%s'\n"), lua2wx(pClass->name).c_str()); ! wxLuaStringToLongHashMap *pHashTable = (wxLuaStringToLongHashMap *)it->second; ! delete pHashTable; ! it->second = 0; ! pDerivedList.erase(it); } ! //else wxPrintf(wxT("wxlua_garbageCollect - Invalid WXLUACLASS derived hashmap iterator key %d!\n"), key); } - //else wxPrintf(wxT("wxlua_garbageCollect - NULL WXLUACLASS!\n")); //wxPrintf(wxT("wxlua_garbageCollect - '%s' tag %d lua %d key %ld tracked %d return value %d\n"), --- 266,302 ---- wxlState.RemoveTrackedObject((void*)key, true); // delete from m_pTrackedList ! lua_pushstring( L, "__wxLuaDerivedFunctions" ); ! lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table ! ! lua_pushlightuserdata(L, (void *)key); ! lua_rawget(L, -2); // pop key, push table or nil ! if (lua_istable(L, -1)) { ! int t = lua_gettop(L); ! lua_pushnil(L); /* first key */ ! while (lua_next(L, t) != 0) ! { ! // uses 'key' (at index -2) and 'value' (at index -1) ! //wxPrintf(wxT("%s - %s\n"), lua2wx(lua_tostring(L, -2)).c_str(), lua2wx(lua_typename(L, lua_type(L, -1))).c_str()); ! if (lua_islightuserdata(L, -1)) ! { ! wxLuaObject* o = (wxLuaObject*)lua_touserdata(L, -1); ! delete o; ! } ! // removes 'value'; keeps 'key' for next iteration ! lua_pop(L, 1); ! } ! ! lua_pop(L, 1); // pop the obj table ! lua_pushlightuserdata(L, (void *)key); ! lua_pushnil(L); ! lua_rawset(L, -3); // nil the obj table ! lua_pop(L, 1); // pop reg table } ! else ! lua_pop(L, 2); // pop the reg table and nil for the obj table } //wxPrintf(wxT("wxlua_garbageCollect - '%s' tag %d lua %d key %ld tracked %d return value %d\n"), *************** *** 338,342 **** else { ! if (wxlState.HasDerivedMethod(pObject, cpIndex)) { fFound = true; --- 356,361 ---- else { ! // if there's a derived method, push it onto the stack to be run ! if (wxlState.HasDerivedMethod(pObject, cpIndex, true)) { fFound = true; *************** *** 412,444 **** { void *pObject = wxlState.ttouserdata(1); ! bool fCreated = false; ! wxLuaStringToLongHashMap *pHashTable = NULL; ! wxLongToLongHashMap::iterator it = wxlState.GetLuaStateData()->m_pDerivedList.find((long) pObject); ! if (it != wxlState.GetLuaStateData()->m_pDerivedList.end()) ! { ! pHashTable = (wxLuaStringToLongHashMap *)it->second; ! } ! if (pHashTable == NULL) { ! 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); } } --- 431,473 ---- { void *pObject = wxlState.ttouserdata(1); ! wxLuaObject* wxlObj = new wxLuaObject(wxlState, 3); ! lua_pushstring( L, "__wxLuaDerivedFunctions" ); ! lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil ! if (!lua_istable(L, -1)) { ! lua_pop(L, 1); // pop nil value ! ! // add new table for this object ! lua_pushlightuserdata(L, (void *)pObject); ! lua_newtable(L); ! lua_rawset(L, -3); ! ! // put the new table back on the top of the stack ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); } ! // see if there already is a method ! lua_pushstring( L, cpIndex ); ! lua_rawget(L, -2); ! ! if (lua_islightuserdata(L, -1)) { ! // already have a method, delete it before replacing it ! wxLuaObject* o = (wxLuaObject*)lua_touserdata( L, -1 ); ! delete o; } ! lua_pop(L, 1); // pop the deleted old object, or nil ! ! lua_pushstring( L, cpIndex ); ! lua_pushlightuserdata(L, (void*)wxlObj); ! lua_rawset(L, -3); ! ! lua_pop(L, 2); // pop the object and overridden function table } } |