From: John L. <jr...@us...> - 2007-08-10 21:23:46
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv23945/wxLua/modules/wxlua/src Modified Files: wxlstate.cpp Log Message: Streamline the creation of a wxLuaState Changed the enums WXLUASTATE_ATTACH/SETSTATE for clarity and completeness. Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.132 retrieving revision 1.133 diff -C2 -d -r1.132 -r1.133 *** wxlstate.cpp 10 Aug 2007 01:41:08 -0000 1.132 --- wxlstate.cpp 10 Aug 2007 21:23:39 -0000 1.133 *************** *** 1325,1330 **** // Clear out the wxLuaState we hashed, note it's not refed so we have ! // NULL it's ref data. Note: even though the lua_State is closed the pointer ! // value is still good. if (m_lua_State != NULL) { --- 1325,1330 ---- // Clear out the wxLuaState we hashed, note it's not refed so we have ! // NULL it's ref data. ! // Note: even though the lua_State is closed the pointer value is still good. if (m_lua_State != NULL) { *************** *** 1440,1444 **** else if (wxlState) { ! return wxLuaState(*wxlState); } --- 1440,1444 ---- else if (wxlState) { ! return wxLuaState(*wxlState); // Ref it } *************** *** 1472,1505 **** { Destroy(); - m_refData = new wxLuaStateRefData(); - - M_WXLSTATEDATA->m_wxlStateData->m_evtHandler = handler; - M_WXLSTATEDATA->m_wxlStateData->m_id = id; lua_State* L = lua_open(); - M_WXLSTATEDATA->m_lua_State = L; - M_WXLSTATEDATA->m_lua_State_static = false; - // load some useful libraries, loads all of them luaL_openlibs(L); luaopen_bit(L); ! // track this newly created lua_State in our hashtable to help us ! // find the wxLuaStateRefData from the lua_State quickly ! wxLuaState* hashState = new wxLuaState(false); ! hashState->SetRefData(m_refData); ! wxLuaStateRefData::s_wxHashMapLuaState[L] = hashState; ! ! // Stick us into the lua_State - push key, value ! wxlua_pushkey_wxLuaState(L); ! lua_pushlightuserdata( L, (void*)hashState ); ! lua_rawset( L, LUA_REGISTRYINDEX ); // set the value ! ! // register handlers to send events ! RegisterFunction(wxlua_printFunction, "print"); ! //RegisterFunction(wxlua_tracebackFunction, "debug.traceback"); ! // now register bindings ! RegisterBindings(true); // alert people that we've been created so they can finish setting us up --- 1472,1485 ---- { Destroy(); lua_State* L = lua_open(); // load some useful libraries, loads all of them luaL_openlibs(L); luaopen_bit(L); ! bool ok = Create(L, wxLUASTATE_USESTATE); ! M_WXLSTATEDATA->m_wxlStateData->m_evtHandler = handler; ! M_WXLSTATEDATA->m_wxlStateData->m_id = id; // alert people that we've been created so they can finish setting us up *************** *** 1510,1528 **** } ! bool wxLuaState::Create(lua_State* L, wxLuaState_Type type) { wxCHECK_MSG(L != NULL, false, wxT("Invalid lua_State")); Destroy(); ! if (type == WXLUASTATE_ATTACH) { Ref(wxLuaStateRefData::GetLuaState(L)); return Ok(); } ! else if (type == WXLUASTATE_SETSTATE) { m_refData = new wxLuaStateRefData(); M_WXLSTATEDATA->m_lua_State = L; ! M_WXLSTATEDATA->m_lua_State_static = true; wxLuaState* hashState = new wxLuaState(false); --- 1490,1510 ---- } ! bool wxLuaState::Create(lua_State* L, int state_type) { wxCHECK_MSG(L != NULL, false, wxT("Invalid lua_State")); Destroy(); ! if (WXLUA_HASBIT(state_type, wxLUASTATE_GETSTATE)) { Ref(wxLuaStateRefData::GetLuaState(L)); return Ok(); } ! ! // state_type == wxLUASTATE_USESTATE or wxLUASTATE_SETSTATE { m_refData = new wxLuaStateRefData(); + M_WXLSTATEDATA->m_lua_State = L; ! M_WXLSTATEDATA->m_lua_State_static = WXLUA_HASBIT(state_type, wxLUASTATE_STATICSTATE); wxLuaState* hashState = new wxLuaState(false); *************** *** 1535,1554 **** lua_rawset( L, LUA_REGISTRYINDEX ); // set the value ! // register handlers to send events ! RegisterFunction(wxlua_printFunction, "print"); ! //RegisterFunction(wxlua_tracebackFunction, "debug.traceback"); ! ! // now register bindings ! RegisterBindings(true); ! return true; } ! m_refData = new wxLuaStateRefData(); ! ! M_WXLSTATEDATA->m_lua_State = L; ! M_WXLSTATEDATA->m_lua_State_static = true; ! ! return true; } --- 1517,1532 ---- lua_rawset( L, LUA_REGISTRYINDEX ); // set the value ! if (WXLUA_HASBIT(state_type, wxLUASTATE_USESTATE)) ! { ! // register handlers to send events ! RegisterFunction(wxlua_printFunction, "print"); ! //RegisterFunction(wxlua_tracebackFunction, "debug.traceback"); ! // now register bindings ! RegisterBindings(true); ! } } ! return Ok(); } |