From: John L. <jr...@us...> - 2005-11-26 03:15:30
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18390/wxLua/modules/wxlua/src Modified Files: internal.cpp wxlstate.cpp Log Message: fix wxMessageDialog in dialogs.i, at least for 2.6 cleanup wxLuaObject to use a single int and enum to store allocation type wxLuaState can now attach to lua_States or wxLuaStateRefData wxLuaDebugEvent to use copy constructor for clone enum debugCommands and debugEvents to wxLuaDebugCommands/Events_Type Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** internal.cpp 25 Nov 2005 19:22:58 -0000 1.10 --- internal.cpp 26 Nov 2005 03:15:19 -0000 1.11 *************** *** 652,668 **** IMPLEMENT_DYNAMIC_CLASS(wxLuaObject, wxObject) ! // Default constructor ! wxLuaObject::wxLuaObject() : m_luaState(NULL), m_iReference(LUA_NOREF), ! m_allocatedBool(false), m_bool(false), ! m_allocatedInt(false), m_int(0), ! m_allocatedString(false), m_allocatedArray(false) { } - // Constructor that is passed a lua state and a parameter index. wxLuaObject::wxLuaObject(lua_State *L, int iParam, int WXUNUSED(iRef)) ! : m_luaState(L), m_allocatedBool(false), m_bool(false), ! m_allocatedInt(false), m_int(0), ! m_allocatedString(false), m_allocatedArray(false) { // set up the reference --- 652,664 ---- IMPLEMENT_DYNAMIC_CLASS(wxLuaObject, wxObject) ! wxLuaObject::wxLuaObject() ! : m_luaState(NULL), m_iReference(LUA_NOREF), ! m_bool(false), m_int(0), m_alloc_flags(wxLUAOBJECT_NONE) { } wxLuaObject::wxLuaObject(lua_State *L, int iParam, int WXUNUSED(iRef)) ! : m_luaState(L), m_bool(false), m_int(0), ! m_alloc_flags(wxLUAOBJECT_NONE) { // set up the reference *************** *** 677,748 **** } - // Return a flag value that indicated whether the - // object is being used by a wxValidator class - // (else 0). - int wxLuaObject::GetAllocationFlags() const - { - int flags = 0; - if (m_allocatedBool) - flags = 1; - if (m_allocatedInt) - flags += 2; - if (m_allocatedString) - flags += 4; - if (m_allocatedArray) - flags += 8; - return flags; - } - - // Allow the flag value to be manipulated. void wxLuaObject::ModifyAllocationFlags(int iValue) { ! if (iValue & 1) ! m_allocatedBool = false; ! if (iValue & 2) ! m_allocatedInt = false; ! if (iValue & 4) ! m_allocatedString = false; ! if (iValue & 8) ! m_allocatedArray = false; ! if (iValue & 16) ! m_allocatedBool = true; ! if (iValue & 32) ! m_allocatedInt = true; ! if (iValue & 64) ! m_allocatedString = true; ! if (iValue & 128) ! m_allocatedArray = true; } - // Get the value of the reference object (or - // a proxy if the object has been aliased for a - // wxValidator class. bool wxLuaObject::GetObject() { ! if (m_allocatedBool) { lua_pushnumber(m_luaState, m_bool); return true; } ! else ! if (m_allocatedInt) { lua_pushnumber(m_luaState, m_int); return true; } ! else ! if (m_allocatedString) { lua_pushstring(m_luaState, wx2lua(m_string)); return true; } ! else ! if (m_allocatedArray) { lua_newtable(m_luaState); ! size_t idx; ! for (idx = 0; idx < m_arrayInt.Count(); ++idx) { lua_pushnumber(m_luaState, m_arrayInt.Item(idx)); --- 673,713 ---- } void wxLuaObject::ModifyAllocationFlags(int iValue) { ! // FIXME - who uses this? ! if (iValue & 1) m_alloc_flags &= (~wxLUAOBJECT_BOOL); ! if (iValue & 2) m_alloc_flags &= (~wxLUAOBJECT_INT); ! if (iValue & 4) m_alloc_flags &= (~wxLUAOBJECT_STRING); ! if (iValue & 8) m_alloc_flags &= (~wxLUAOBJECT_ARRAYINT); ! if (iValue & 16) m_alloc_flags |= wxLUAOBJECT_BOOL; ! if (iValue & 32) m_alloc_flags |= wxLUAOBJECT_INT; ! if (iValue & 64) m_alloc_flags |= wxLUAOBJECT_STRING; ! if (iValue & 128) m_alloc_flags |= wxLUAOBJECT_ARRAYINT; } bool wxLuaObject::GetObject() { ! if (HasAllocationFlag(wxLUAOBJECT_BOOL)) { lua_pushnumber(m_luaState, m_bool); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_INT)) { lua_pushnumber(m_luaState, m_int); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_STRING)) { lua_pushstring(m_luaState, wx2lua(m_string)); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_ARRAYINT)) { lua_newtable(m_luaState); ! size_t idx, count = m_arrayInt.Count(); ! for (idx = 0; idx < count; ++idx) { lua_pushnumber(m_luaState, m_arrayInt.Item(idx)); *************** *** 751,759 **** return true; } ! return (m_iReference != LUA_NOREF && ! tget(m_luaState, m_iReference) != 0); } - // Set the reference and lua state up from a supplied parameter. void wxLuaObject::SetObject(lua_State *L, int iParam) { --- 716,723 ---- return true; } ! ! return (m_iReference != LUA_NOREF) && (tget(m_luaState, m_iReference) != 0); } void wxLuaObject::SetObject(lua_State *L, int iParam) { *************** *** 762,766 **** } - // Remove any existing reference and allocated another void wxLuaObject::SetObject(int iParam) { --- 726,729 ---- *************** *** 776,786 **** } - // The following methods are used by the wxValidator interface bool *wxLuaObject::GetBoolPtr() { if ((m_luaState != NULL) && (m_iReference != LUA_NOREF) && GetObject()) { ! m_bool = (lua_tonumber(m_luaState, -1) != 0); ! m_allocatedBool = true; } return &m_bool; --- 739,748 ---- } bool *wxLuaObject::GetBoolPtr() { if ((m_luaState != NULL) && (m_iReference != LUA_NOREF) && GetObject()) { ! m_bool = (lua_tonumber(m_luaState, -1) != 0); ! m_alloc_flags |= wxLUAOBJECT_BOOL; } return &m_bool; *************** *** 792,796 **** { m_int = (int) lua_tonumber(m_luaState, -1); ! m_allocatedInt = true; } return &m_int; --- 754,758 ---- { m_int = (int) lua_tonumber(m_luaState, -1); ! m_alloc_flags |= wxLUAOBJECT_INT; } return &m_int; *************** *** 801,806 **** if ((m_luaState != NULL) && (m_iReference != LUA_NOREF) && GetObject()) { ! m_string = lua2wx(lua_tostring(m_luaState, -1)); ! m_allocatedString = true; } return &m_string; --- 763,768 ---- if ((m_luaState != NULL) && (m_iReference != LUA_NOREF) && GetObject()) { ! m_string = lua2wx(lua_tostring(m_luaState, -1)); ! m_alloc_flags |= wxLUAOBJECT_STRING; } return &m_string; *************** *** 824,828 **** } lua_pop(m_luaState, 1); ! m_allocatedArray = true; } return &m_arrayInt; --- 786,790 ---- } lua_pop(m_luaState, 1); ! m_alloc_flags |= wxLUAOBJECT_ARRAYINT; } return &m_arrayInt; Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** wxlstate.cpp 25 Nov 2005 18:52:21 -0000 1.3 --- wxlstate.cpp 26 Nov 2005 03:15:19 -0000 1.4 *************** *** 194,200 **** m_pDerivedList = new wxHashTable(wxKEY_INTEGER); m_pTrackedList = new wxHashTable(wxKEY_INTEGER); ! m_pAppHandlerList = new wxList; ! m_pDestroyHandlerList = new wxList; ! m_pWindowList = new wxList; } --- 194,200 ---- m_pDerivedList = new wxHashTable(wxKEY_INTEGER); m_pTrackedList = new wxHashTable(wxKEY_INTEGER); ! //m_pAppHandlerList = new wxList; ! //m_pDestroyHandlerList = new wxList; ! //m_pWindowList = new wxList; } *************** *** 204,211 **** } ! wxLuaStateRefData::wxLuaStateRefData( const wxLuaStateRefData& data ) ! { ! ! } wxLuaStateRefData::~wxLuaStateRefData() --- 204,210 ---- } ! //wxLuaStateRefData::wxLuaStateRefData( const wxLuaStateRefData& data ) ! //{ ! //} wxLuaStateRefData::~wxLuaStateRefData() *************** *** 213,222 **** Destroy(true); - ClearCallbacks(); delete m_pDerivedList; delete m_pTrackedList; ! delete m_pAppHandlerList; ! delete m_pDestroyHandlerList; ! delete m_pWindowList; } --- 212,220 ---- Destroy(true); delete m_pDerivedList; delete m_pTrackedList; ! //delete m_pAppHandlerList; ! //delete m_pDestroyHandlerList; ! //delete m_pWindowList; } *************** *** 227,235 **** // remove deleted windows first ! if (m_pWindowList && m_pWindowList->GetCount()) ! wxLuaCleanupWindows(m_pWindowList, true); // are there still windows? ask to abort deleting them if !force ! if (m_pWindowList && m_pWindowList->GetCount()) { int ret = wxOK; --- 225,233 ---- // remove deleted windows first ! if (m_pWindowList.GetCount()) ! wxLuaCleanupWindows(&m_pWindowList, true); // are there still windows? ask to abort deleting them if !force ! if (m_pWindowList.GetCount() != 0) { int ret = wxOK; *************** *** 248,252 **** // delete windows and their eventhandler since they delete the LuaCallbacks // which require a lua_State ! wxLuaCleanupWindows(m_pWindowList, false); // wait for wxWindow::Destroy() to really delete the windows //wxYieldIfNeeded(); --- 246,250 ---- // delete windows and their eventhandler since they delete the LuaCallbacks // which require a lua_State ! wxLuaCleanupWindows(&m_pWindowList, false); // wait for wxWindow::Destroy() to really delete the windows //wxYieldIfNeeded(); *************** *** 255,258 **** --- 253,261 ---- CleanupWxLua(m_lua_State, !m_lua_State_static); s_wxHashMapLuaStateRefData.erase(m_lua_State); + ClearCallbacks(); + + m_pDerivedList->DeleteContents(false); + m_pTrackedList->DeleteContents(false); + m_pWindowList.DeleteContents(false); m_lua_State = NULL; *************** *** 264,268 **** { // remove any and all callbacks that use this event handler since its gone ! wxNode* node = m_pAppHandlerList->GetFirst(); while (node) { --- 267,271 ---- { // remove any and all callbacks that use this event handler since its gone ! wxNode* node = m_pAppHandlerList.GetFirst(); while (node) { *************** *** 277,281 **** node = node->GetNext(); } ! node = m_pDestroyHandlerList->GetFirst(); while (node) { --- 280,284 ---- node = node->GetNext(); } ! node = m_pDestroyHandlerList.GetFirst(); while (node) { *************** *** 292,298 **** // don't "own" pointers to wxLuaCallbacks, let wxEventHandler do it ! m_pAppHandlerList->DeleteContents(false); // don't delete wxLuaDestroyCallbacks, let wxEventHandler do it ! m_pDestroyHandlerList->DeleteContents(false); } --- 295,301 ---- // don't "own" pointers to wxLuaCallbacks, let wxEventHandler do it ! m_pAppHandlerList.DeleteContents(false); // don't delete wxLuaDestroyCallbacks, let wxEventHandler do it ! m_pDestroyHandlerList.DeleteContents(false); } *************** *** 330,337 **** return new wxLuaStateRefData; } ! wxObjectRefData *wxLuaState::CloneRefData(const wxObjectRefData *data) const ! { ! return new wxLuaStateRefData(*(const wxLuaStateRefData *)data); ! } void wxLuaState::Create( const wxLuaState& wxlState ) --- 333,340 ---- return new wxLuaStateRefData; } ! //wxObjectRefData *wxLuaState::CloneRefData(const wxObjectRefData *data) const ! //{ ! // return new wxLuaStateRefData(*(const wxLuaStateRefData *)data); ! //} void wxLuaState::Create( const wxLuaState& wxlState ) *************** *** 340,361 **** } ! bool wxLuaState::Create(lua_State* L, wxLuaState_Type type) // FIXME FINISH THIS { ! if (Ok()) Destroy(); ! m_refData = new wxLuaStateRefData(); ! // create a lua instance ! if (L != NULL) ! { ! M_WXLSTATEDATA->m_lua_State = L; ! M_WXLSTATEDATA->m_lua_State_static = true; ! } ! else ! { ! M_WXLSTATEDATA->m_lua_State = lua_open(); ! M_WXLSTATEDATA->m_lua_State_static = false; ! L = M_WXLSTATEDATA->m_lua_State; ! } // load some useful libraries --- 343,354 ---- } ! bool wxLuaState::Create() { ! if (GetRefData() != NULL) UnRef(); m_refData = new wxLuaStateRefData(); ! lua_State* L = lua_open(); ! M_WXLSTATEDATA->m_lua_State = L; ! M_WXLSTATEDATA->m_lua_State_static = false; // load some useful libraries *************** *** 388,391 **** --- 381,425 ---- // now register bindings RegisterBindings(true); + return true; + } + + bool wxLuaState::Create(lua_State* L, wxLuaState_Type type) + { + wxCHECK_MSG(L != NULL, false, wxT("Invalid lua_State")); + if (GetRefData() != NULL) UnRef(); + + if (type == WXLUASTATE_ATTACH) + { + wxLuaStateRefData *refData = wxLuaStateRefData::FindLuaStateRefData(L); + wxCHECK_MSG(refData != NULL, false, wxT("Unable to find lua_State")); + return Create(refData); + } + + m_refData = new wxLuaStateRefData(); + + M_WXLSTATEDATA->m_lua_State = L; + M_WXLSTATEDATA->m_lua_State_static = true; + + return true; + } + + bool wxLuaState::Create(wxLuaStateRefData* refData) + { + // nothing to be done + if (m_refData == refData) + return true; + + // delete reference to old data + UnRef(); + + // reference new data + if ( refData ) + { + // we need to inc the ref count + wxLuaState lS; + lS.SetRefData(refData); + Ref(lS); + lS.SetRefData(NULL); + } return true; |