From: John L. <jr...@us...> - 2006-08-28 05:26:24
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1034/wxLua/modules/wxlua/src Modified Files: Makefile internal.cpp wxlbind.cpp wxlcallb.cpp wxlstate.cpp Log Message: Finished cleaning up the code, removed all code from internal.h and internal.cpp and moved it to other files. Do not #include internal.h anymore! Have the functions in wxLuaState that only call C lua funcs call C helper funcs in wxlstate.cpp so that you don't have to create a wxLuaState if you don't really need it. Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/Makefile,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile 13 May 2006 21:05:36 -0000 1.8 --- Makefile 28 Aug 2006 05:26:20 -0000 1.9 *************** *** 53,57 **** HEADERS = \ ../include/wxldefs.h \ - ../include/internal.h \ ../include/wxlua.h \ ../include/wxlbind.h \ --- 53,56 ---- *************** *** 60,64 **** SOURCES = \ - internal.cpp \ wxlbind.cpp \ wxlcallb.cpp \ --- 59,62 ---- Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** internal.cpp 30 May 2006 22:56:29 -0000 1.42 --- internal.cpp 28 Aug 2006 05:26:20 -0000 1.43 *************** *** 29,621 **** #ifndef WX_PRECOMP #include "wx/wx.h" - #include "wx/app.h" #endif #include "wxlua/include/internal.h" - // lua registry table - const char wxLuaReferences[] = "wxLuaReferences"; - const char wxLuaNull[] = "wxNull"; - - wxString GetSourceLine(lua_State *L) - { - wxString msg; - lua_Debug luaDebug = INIT_LUA_DEBUG; - - if (lua_getinfo(L, "Sln", &luaDebug)) - { - wxString name = lua2wx(luaDebug.name); - wxString source = lua2wx(luaDebug.source); - int line = luaDebug.currentline; - - msg = wxString::Format(wxT("%s %s: (%d)"), name.c_str(), source.c_str(), line); - } - - return msg; - } - - //----------------------------------------------------------------------------- - // wxLuaObject - //----------------------------------------------------------------------------- - IMPLEMENT_DYNAMIC_CLASS(wxLuaObject, wxObject) - - wxLuaObject::wxLuaObject() - : 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_wxlState(L), m_bool(false), m_int(0), - m_alloc_flags(wxLUAOBJECT_NONE) - { - m_iReference = m_wxlState.tinsert(iParam); - } - - wxLuaObject::wxLuaObject(const wxLuaState& wxlState, int iParam, int WXUNUSED(iRef)) - : m_wxlState(wxlState), m_bool(false), m_int(0), - m_alloc_flags(wxLUAOBJECT_NONE) - { - // set up the reference - m_iReference = m_wxlState.tinsert(iParam); - } - - wxLuaObject::~wxLuaObject() - { - // If a refererence exists, remove it, don't bother if lua is being closed - if ((m_iReference != LUA_NOREF) && m_wxlState.Ok() && !m_wxlState.IsClosing()) - m_wxlState.tremove(m_iReference); - } - - void wxLuaObject::ModifyAllocationFlags(int iValue) - { - // FIXME - who uses and knows how to use 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() - { - wxCHECK_MSG(m_wxlState.Ok(), false, wxT("Invalid wxLuaState")); - lua_State* L = GetLuaState(); - - if (HasAllocationFlag(wxLUAOBJECT_BOOL)) - { - lua_pushnumber(L, m_bool); - return true; - } - else if (HasAllocationFlag(wxLUAOBJECT_INT)) - { - lua_pushnumber(L, m_int); - return true; - } - else if (HasAllocationFlag(wxLUAOBJECT_STRING)) - { - lua_pushstring(L, wx2lua(m_string)); - return true; - } - else if (HasAllocationFlag(wxLUAOBJECT_ARRAYINT)) - { - lua_newtable(L); - - size_t idx, count = m_arrayInt.Count(); - for (idx = 0; idx < count; ++idx) - { - lua_pushnumber(L, m_arrayInt.Item(idx)); - lua_rawseti(L, -2, idx); - } - return true; - } - - return (m_iReference != LUA_NOREF) && (m_wxlState.tget(m_iReference) != 0); - } - - void wxLuaObject::SetObject(lua_State *L, int iParam) - { - m_wxlState.Create(L); - SetObject(iParam); - } - - void wxLuaObject::SetObject(int iParam) - { - if (m_wxlState.Ok() && (m_iReference != LUA_NOREF)) // FIXME should this error out? - m_wxlState.tremove(m_iReference); - - m_iReference = LUA_NOREF; - - if (m_wxlState.Ok()) - m_iReference = m_wxlState.tinsert(iParam); - } - - bool *wxLuaObject::GetBoolPtr() - { - if (m_wxlState.Ok() && (m_iReference != LUA_NOREF) && GetObject()) - { - m_bool = (lua_tonumber(GetLuaState(), -1) != 0); - m_alloc_flags |= wxLUAOBJECT_BOOL; - } - return &m_bool; - } - - int *wxLuaObject::GetIntPtr() - { - if (m_wxlState.Ok() && (m_iReference != LUA_NOREF) && GetObject()) - { - m_int = (int) lua_tonumber(GetLuaState(), -1); - m_alloc_flags |= wxLUAOBJECT_INT; - } - return &m_int; - } - - wxString *wxLuaObject::GetStringPtr() - { - if (m_wxlState.Ok() && (m_iReference != LUA_NOREF) && GetObject()) - { - m_string = lua2wx(lua_tostring(GetLuaState(), -1)); - m_alloc_flags |= wxLUAOBJECT_STRING; - } - return &m_string; - } - - wxArrayInt *wxLuaObject::GetArrayPtr() - { - if (m_wxlState.Ok() && (m_iReference != LUA_NOREF) && GetObject()) - { - lua_State* L = GetLuaState(); - if (lua_istable(L, -1)) - { - int idx, nItems = luaL_getn(L, -1); - for (idx = 1; idx <= nItems; ++idx) - { - lua_rawgeti(L, -1, idx); - int iValue = (int) wxLua_lua_getnumbertype(L, -1); - m_arrayInt.Add(iValue); - lua_pop(L, 1); - } - } - lua_pop(L, 1); - m_alloc_flags |= wxLUAOBJECT_ARRAYINT; - } - return &m_arrayInt; - } - - // ---------------------------------------------------------------------------- - // txxx functions to make lua calls easier - // ---------------------------------------------------------------------------- - - int LUACALL wxLua_lua_tinsert(lua_State *L, int iParam) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - return wxlState.tinsert(iParam); - } - - bool LUACALL wxLua_lua_tremove(lua_State *L, int iReference) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), false, wxT("Invalid wxLuaState")); - return wxlState.tremove(iReference); - } - - bool LUACALL wxLua_lua_tget(lua_State *L, int iIndex) - { - if (iIndex == LUA_REFNIL) - { - lua_pushnil(L); - return true; - } - - int iCount; - bool ret = false; // false indicates index out of range - - wxLua_lua_tpushwxLuaReferences(L); - lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (refs table) - - lua_pushliteral(L, "n"); // push 'n' as key - lua_rawget(L, -2); // pop key, push result - iCount = (int) lua_tonumber(L, -1); // get result value - lua_pop(L, 1); // pop result - - if (iIndex > 0 && iIndex <= iCount) // ensure in range - { - lua_rawgeti(L, -1, iIndex); // push result - ret = true; - } - else - lua_pushnil(L); // push result - - lua_remove(L, -2); // balance stack - - return ret; - } - - int LUACALL wxLua_lua_tgetn(lua_State *L) - { - wxLua_lua_tpushwxLuaReferences(L); - lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (refs table) - - lua_pushliteral(L, "n"); - lua_rawget(L, -2); - - int n; - if (lua_isnumber(L, -1)) - { - n = (int) lua_tonumber(L, -1); - } - else - { - /* must count elements */ - n = 0; - for (;;) - { - lua_rawgeti(L, -2, ++n); - bool isNil = lua_isnil(L, -1); - lua_pop(L, 1); - if (isNil) - break; - } - --n; - } - lua_pop(L, 2); - return n; - } - - void LUACALL wxLua_lua_terror(lua_State *L, const char *errorMsg) - { - lua_pushstring(L, errorMsg); - lua_error(L); - } - - void LUACALL wxLua_lua_tpushusertag(lua_State *L, const void *u, int tag) - { - const void **ptr = (const void **) lua_newuserdata(L, sizeof(void *)); - if (ptr != NULL) - { - *ptr = u; - if ((tag != TLUA_NOTAG) && wxLua_lua_tget(L, tag)) - { - if (lua_setmetatable(L, -2) == 0) - wxLua_lua_terror(L, "wxLua: Unable to set metatable"); - } - } - else - wxLua_lua_terror(L, "wxLua: Out of memory"); - } - - void LUACALL wxLua_lua_tsettag(lua_State *L, int tag) - { - if ((tag != TLUA_NOTAG) && wxLua_lua_tget(L, tag)) - { - if (!lua_setmetatable(L, -2)) - wxLua_lua_terror(L, "wxLua: Unable to set metatable"); - } - } - - int LUACALL wxLua_lua_ttag(lua_State *L, int index) - { - int tag = TLUA_NOTAG; - if (lua_getmetatable(L, index) != 0) - { - lua_pushliteral(L, "tag"); - lua_rawget(L, -2); - if (lua_isnumber(L, -1)) - { - tag = (int) lua_tonumber(L, -1); - } - lua_pop(L, 2); - } - return tag; - } - - void * LUACALL wxLua_lua_ttouserdata(lua_State *L, int index, bool reset /* = false*/) - { - void *pdata = NULL; - void **ptr = (void **) lua_touserdata(L, index); - if (ptr != NULL) - { - pdata = *ptr; - if (reset) - *ptr = NULL; - } - return pdata; - } - - int LUACALL wxLua_lua_tnewtag(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - return wxlState.tnewtag(); - } - - bool LUACALL wxLua_lua_tsettagmethod(lua_State *L, int tag, const char *method, lua_CFunction func, void *pClass /* = NULL*/) - { - if ((tag != TLUA_NOTAG) && wxLua_lua_tget(L, tag)) - { - if (pClass != NULL) - { - lua_pushstring(L, method); - lua_pushlightuserdata(L, pClass); - lua_pushcclosure(L, func, 1); - } - else - { - lua_pushstring(L, method); - lua_pushcclosure(L, func, 0); - } - lua_rawset(L, -3); - lua_pop(L, 1); - return true; - } - return false; - } - - void LUACALL wxLua_lua_tpushwxLuaReferences(lua_State *L) - { - lua_pushlstring(L, wxLuaReferences, sizeof(wxLuaReferences)-1); - // FIXME this used to be #define tpushliteralstring(str, sizeof(str)-1) - //lua_pushstring(L, wxLuaReferences); //, strlen(wxLuaReferences)-1); - } - - void LUACALL wxLua_lua_tpushwxLuaNull(lua_State *L) - { - lua_pushlstring(L, wxLuaNull, sizeof(wxLuaNull)-1); - //lua_pushstring(L, wxLuaNull); //, strlen(wxLuaNull)-1); - } - - - // Validate that the object at the stack index specified is a string object - // or that the object can be converted to a string. - // Return the string. - const char * LUACALL wxLua_lua_getstringtype(lua_State *L, int iParam) - { - switch(lua_type(L, iParam)) - { - case LUA_TNIL: - case LUA_TSTRING: - case LUA_TNUMBER: - break; - default: - wxLua_lua_terror(L, wx2lua(wxString::Format(_("wxLua: Expected string for parameter %d."), iParam))); - break; - } - - return lua_tostring(L, iParam); - } - - // Validate that the object at the stack index specified is a boolean object - // or that the object can be converted to a boolean. - // Return the boolean. - bool LUACALL wxLua_lua_getbooleantype(lua_State *L, int iParam) - { - switch(lua_type(L, iParam)) - { - case LUA_TNIL: - case LUA_TNUMBER: - case LUA_TBOOLEAN: - /*OK*/ - break; - default: - wxLua_lua_terror(L, wx2lua(wxString::Format(_("wxLua: Expected boolean for parameter %d."), iParam))); - break; - } - - int num = (int) lua_toboolean(L, iParam); - - // This test is not reliable false == 0 but true !=0 not true == 1 - // The paramter can be the result of evaluating an expression as well as one of the two - // boolean constants. - // if (!(num == true) || !(num == false)) - // terror(L, wxString::Format("wxLua: Expected 'true' or 'false' for parameter %d.", iParam)); - - return num ? true : false; - } - - // Validate that the object at the stack index specified is a enumeration object - // or that the object can be converted to a enumeration. - // Return the enumeration value. - long LUACALL wxLua_lua_getenumerationtype(lua_State *L, int iParam) - { - switch(lua_type(L, iParam)) - { - //case LUA_TNIL: - //case LUA_TSTRING: - case LUA_TNUMBER: - /*OK*/ - break; - default: - wxLua_lua_terror(L, wx2lua(wxString::Format(_("wxLua: Expected enum number for parameter %d."), iParam))); - break; - } - - return (long) lua_tonumber(L, iParam); - } - - // Validate that the object at the stack index specified is a enumeration object - // or that the object can be converted to a enumeration. - // Return the enumeration value. - double LUACALL wxLua_lua_getnumbertype(lua_State *L, int iParam) - { - switch(lua_type(L, iParam)) - { - case LUA_TNIL: - case LUA_TSTRING: - case LUA_TNUMBER: - case LUA_TBOOLEAN: - /*OK*/ - break; - default: - wxLua_lua_terror(L, wx2lua(wxString::Format(_("wxLua: Expected number for parameter %d."), iParam))); - break; - } - - return lua_tonumber(L, iParam); - } - - // Validate that the object at the stack index specified is a table object - // Convert the table to an array of wxStrings. This assumes that each - // numeric entry in the table is a string object or can be converted to a string - // Return a pointer to the array of wxStrings. - wxString * LUACALL wxLua_lua_getwxstringarray(lua_State *L, int iParam, int &count) - { - int idx; - wxString *pItems = NULL; - - count = 0; - - if (lua_istable(L, iParam)) - { - int nItems = luaL_getn(L, iParam); - if (nItems > 0) - pItems = new wxString[nItems]; - if (pItems != NULL) - { - for (idx = 1; idx <= nItems; ++idx) - { - lua_rawgeti(L, iParam, idx); - const char *pString = wxLua_lua_getstringtype(L, -1); - if (pString != NULL) - pItems[count++] = lua2wx(pString); - lua_pop(L, 1); - } - } - } - return pItems; - } - - // Convert a wxArrayString object to an table of strings - int LUACALL wxLua_lua_pushwxarraystringtable(lua_State *L, wxArrayString &files) - { - lua_newtable(L); - - size_t idx, count = files.Count(); - for (idx = 0; idx < count; ++idx) - { - const wxString &item = files.Item(idx); - lua_pushstring(L, wx2lua(item)); - lua_rawseti(L, -2, idx + 1); - } - return idx; - } - - int LUACALL wxLua_lua_pushwxarrayinttable(lua_State *L, const wxArrayInt &table) - { - lua_newtable(L); - - size_t idx, count = table.Count(); - for (idx = 0; idx < count; ++idx) - { - int item = table.Item(idx); - lua_pushnumber(L, item); - lua_rawseti(L, -2, idx + 1); - } - return idx; - } - - // Validate that the object at the stack index specified is a table object - // Convert the table to an array of ints. This assumes that each - // numeric entry in the table is a numeric object or can be converted to a number - // Return a pointer to the array of ints. - int * LUACALL wxLua_lua_getintarray(lua_State *L, int iParam, int &count) - { - int idx; - int *pItems = NULL; - - count = 0; - - if (lua_istable(L, iParam)) - { - int nItems = luaL_getn(L, iParam); - if (nItems > 0) - pItems = new int[nItems]; - if (pItems != NULL) - { - for (idx = 1; idx <= nItems; ++idx) - { - lua_rawgeti(L, iParam, idx); - int iValue = (int) wxLua_lua_getnumbertype(L, -1); - pItems[count++] = iValue; - lua_pop(L, 1); - } - } - } - return pItems; - } - - int LUACALL wxLua_lua_getwxarrayint(lua_State *L, int iParam, wxArrayInt &intArray) - { - int idx, count = 0; - intArray.Clear(); - - if (lua_istable(L, iParam)) - { - int nItems = luaL_getn(L, iParam); - if (nItems > 0) - { - for (idx = 1; idx <= nItems; ++idx) - { - lua_rawgeti(L, iParam, idx); - if (lua_isnumber(L, -1)) - { - int iValue = (int) wxLua_lua_getnumbertype(L, -1); - intArray.Add(iValue); - ++count; - } - lua_pop(L, 1); - } - } - } - return count; - } - - const char ** LUACALL wxLua_lua_getchararray(lua_State *L, int iParam, int &count) - { - int idx; - const char **pItems = NULL; - - count = 0; - - if (lua_istable(L, iParam)) - { - int nItems = luaL_getn(L, iParam); - if (nItems > 0) - pItems = new const char *[nItems]; - if (pItems != NULL) - { - for (idx = 1; idx <= nItems; ++idx) - { - lua_rawgeti(L, iParam, idx); - const char *pValue = wxLua_lua_getstringtype(L, -1); - pItems[count++] = pValue; - lua_pop(L, 1); - } - } - } - return pItems; - } --- 29,34 ---- Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** wxlstate.cpp 21 Jun 2006 03:58:03 -0000 1.73 --- wxlstate.cpp 28 Aug 2006 05:26:20 -0000 1.74 *************** *** 42,46 **** #include "wxlua/include/wxlstate.h" #include "wxlua/include/wxlcallb.h" - #include "wxlua/include/internal.h" #include "wx/tokenzr.h" --- 42,45 ---- *************** *** 48,52 **** extern int wxLuaClassListCompareByTag(const void *p1, const void *p2); // wxlbind.cpp [...1221 lines suppressed...] } ! wxString wxLuaState::lua_TypeName(int type) const { wxCHECK_MSG(Ok(), wxEmptyString, wxT("Invalid wxLuaState")); ! return lua2wx(lua_typename(M_WXLSTATEDATA->m_lua_State, type)); } *************** *** 3529,3533 **** wxLuaEvent::wxLuaEvent(wxEventType commandType, wxWindowID id, const wxLuaState& wxlState) ! : wxNotifyEvent(commandType, id), m_wxlState(wxlState), m_debug_hook_break(false), m_lua_Debug(NULL) --- 3695,3699 ---- wxLuaEvent::wxLuaEvent(wxEventType commandType, wxWindowID id, const wxLuaState& wxlState) ! :wxNotifyEvent(commandType, id), m_wxlState(wxlState), m_debug_hook_break(false), m_lua_Debug(NULL) Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** wxlbind.cpp 21 Jun 2006 03:58:03 -0000 1.37 --- wxlbind.cpp 28 Aug 2006 05:26:20 -0000 1.38 *************** *** 23,27 **** #include "wxlua/include/wxlbind.h" #include "wxlua/include/wxlstate.h" - #include "wxlua/include/internal.h" #include "wx/listimpl.cpp" --- 23,26 ---- *************** *** 45,48 **** --- 44,218 ---- WX_DEFINE_LIST(wxLuaBindingList); + //----------------------------------------------------------------------------- + // wxLuaObject + //----------------------------------------------------------------------------- + IMPLEMENT_DYNAMIC_CLASS(wxLuaObject, wxObject) + + wxLuaObject::wxLuaObject() + : m_wxlState(NULL), m_iReference(LUA_NOREF), + m_bool(false), m_int(0), m_alloc_flags(wxLUAOBJECT_NONE) + { + m_wxlState = new wxLuaState(false); // always created even if invalid + } + + wxLuaObject::wxLuaObject(lua_State *L, int iParam, int WXUNUSED(iRef)) + : m_wxlState(NULL), + m_bool(false), m_int(0), m_alloc_flags(wxLUAOBJECT_NONE) + { + m_wxlState = new wxLuaState(L); + m_iReference = m_wxlState->tinsert(iParam); + } + + wxLuaObject::wxLuaObject(const wxLuaState& wxlState, int iParam, int WXUNUSED(iRef)) + : m_wxlState(NULL), + m_bool(false), m_int(0), m_alloc_flags(wxLUAOBJECT_NONE) + { + m_wxlState = new wxLuaState(wxlState); + // set up the reference + m_iReference = m_wxlState->tinsert(iParam); + } + + wxLuaObject::~wxLuaObject() + { + // If a refererence exists, remove it, don't bother if lua is being closed + if ((m_iReference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing()) + m_wxlState->tremove(m_iReference); + + delete m_wxlState; + } + + wxLuaState wxLuaObject::GetwxLuaState() const + { + return (m_wxlState != NULL) ? *m_wxlState : wxNullLuaState; + } + lua_State* wxLuaObject::GetLuaState() const + { + return GetwxLuaState().GetLuaState(); + } + + void wxLuaObject::ModifyAllocationFlags(int iValue) + { + // FIXME - who uses and knows how to use 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() + { + lua_State* L = GetLuaState(); + wxCHECK_MSG(L, false, wxT("Invalid wxLuaState")); + + if (HasAllocationFlag(wxLUAOBJECT_BOOL)) + { + lua_pushnumber(L, m_bool); + return true; + } + else if (HasAllocationFlag(wxLUAOBJECT_INT)) + { + lua_pushnumber(L, m_int); + return true; + } + else if (HasAllocationFlag(wxLUAOBJECT_STRING)) + { + lua_pushstring(L, wx2lua(m_string)); + return true; + } + else if (HasAllocationFlag(wxLUAOBJECT_ARRAYINT)) + { + lua_newtable(L); + + size_t idx, count = m_arrayInt.Count(); + for (idx = 0; idx < count; ++idx) + { + lua_pushnumber(L, m_arrayInt.Item(idx)); + lua_rawseti(L, -2, idx); + } + return true; + } + + return (m_iReference != LUA_NOREF) && (m_wxlState->tget(m_iReference) != 0); + } + + void wxLuaObject::SetObject(lua_State *L, int iParam) + { + wxCHECK_RET(L, wxT("Invalid lua_State")); + m_wxlState->Create(L); + SetObject(iParam); + } + + void wxLuaObject::SetObject(int iParam) + { + if (m_wxlState->Ok() && (m_iReference != LUA_NOREF)) // FIXME should this error out? + m_wxlState->tremove(m_iReference); + + m_iReference = LUA_NOREF; + + if (m_wxlState->Ok()) + m_iReference = m_wxlState->tinsert(iParam); + } + + bool *wxLuaObject::GetBoolPtr() + { + if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) + { + m_bool = (lua_tonumber(GetLuaState(), -1) != 0); + m_alloc_flags |= wxLUAOBJECT_BOOL; + } + return &m_bool; + } + + int *wxLuaObject::GetIntPtr() + { + if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) + { + m_int = (int) lua_tonumber(GetLuaState(), -1); + m_alloc_flags |= wxLUAOBJECT_INT; + } + return &m_int; + } + + wxString *wxLuaObject::GetStringPtr() + { + if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) + { + m_string = lua2wx(lua_tostring(GetLuaState(), -1)); + m_alloc_flags |= wxLUAOBJECT_STRING; + } + return &m_string; + } + + wxArrayInt *wxLuaObject::GetArrayPtr() + { + if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) + { + lua_State* L = GetLuaState(); + if (lua_istable(L, -1)) + { + int idx, nItems = luaL_getn(L, -1); + for (idx = 1; idx <= nItems; ++idx) + { + lua_rawgeti(L, -1, idx); + int iValue = (int) m_wxlState->GetNumberType(-1); + m_arrayInt.Add(iValue); + lua_pop(L, 1); + } + } + lua_pop(L, 1); + m_alloc_flags |= wxLUAOBJECT_ARRAYINT; + } + return &m_arrayInt; + } + + // ---------------------------------------------------------------------------- + // wxLua_AddToTrackedMemoryList + // ---------------------------------------------------------------------------- + void LUACALL wxLua_AddToTrackedMemoryList(wxLuaState& wxlState, wxObject *pObject) { *************** *** 50,53 **** --- 220,227 ---- } + // ---------------------------------------------------------------------------- + // wxLua_lua_tableErrorHandler + // ---------------------------------------------------------------------------- + static int LUACALL wxLua_lua_tableErrorHandler(lua_State *L) { *************** *** 56,60 **** } ! // if the class defines a gc function, then call it. int LUACALL wxLua_lua_garbageCollect(lua_State *L) { --- 230,237 ---- } ! // ---------------------------------------------------------------------------- ! // wxLua_lua_garbageCollect - if the class defines a gc function, then call it. ! // ---------------------------------------------------------------------------- ! int LUACALL wxLua_lua_garbageCollect(lua_State *L) { *************** *** 91,96 **** //else wxPrintf(wxT("wxLua_lua_garbageCollect - Invalid WXLUACLASS derived hashmap iterator key %d!\n"), key); ! int iMethod; ! for (iMethod = 0; iMethod < pClass->num_methods; ++iMethod) { WXLUAMETHOD *pMethod = pClass->methods + iMethod; --- 268,273 ---- //else wxPrintf(wxT("wxLua_lua_garbageCollect - Invalid WXLUACLASS derived hashmap iterator key %d!\n"), key); ! int iMethod, method_count = pClass->num_methods; ! for (iMethod = 0; iMethod < method_count; ++iMethod) { WXLUAMETHOD *pMethod = pClass->methods + iMethod; *************** *** 110,115 **** } ! static const char baseString[] = "base_"; ! // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (gettable tag method). --- 287,293 ---- } ! // ---------------------------------------------------------------------------- ! // wxLua_lua_getTableFunc ! // // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (gettable tag method). *************** *** 118,121 **** --- 296,303 ---- // will be called to invoke the function. // todo: Handling of properties + // ---------------------------------------------------------------------------- + + static const char baseString[] = "base_"; + int LUACALL wxLua_lua_getTableFunc(lua_State *L) { *************** *** 195,202 **** } ! // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (settable tag method). // todo: Handling of properties int LUACALL wxLua_lua_setTableFunc(lua_State *L) { --- 377,388 ---- } ! // ---------------------------------------------------------------------------- ! // wxLua_lua_setTableFunc ! // // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (settable tag method). // todo: Handling of properties + // ---------------------------------------------------------------------------- + int LUACALL wxLua_lua_setTableFunc(lua_State *L) { *************** *** 264,267 **** --- 450,454 ---- // ---------------------------------------------------------------------------- // Function to compare to events by eventType + // ---------------------------------------------------------------------------- int wxLuaEventListCompareFn(const void *p1, const void *p2) { *************** *** 269,273 **** --- 456,462 ---- } + // ---------------------------------------------------------------------------- // Function to compare the class tag of two classes + // ---------------------------------------------------------------------------- int wxLuaClassListCompareByTag(const void *p1, const void *p2) { *************** *** 385,391 **** if ((binding->GetLuaNamespace() == m_nameSpace) && (binding->m_wxLuaTable >= 0)) - { namedBinding = binding; - } } --- 574,578 ---- *************** *** 406,410 **** void LUACALL wxLuaBinding::RegisterGeneratedClasses(const wxLuaState& wxlState_, int tableOffset, bool registerTypes) { ! static const luaL_reg funcTable[] = { {"__gc", wxLua_lua_garbageCollect }, --- 593,597 ---- void LUACALL wxLuaBinding::RegisterGeneratedClasses(const wxLuaState& wxlState_, int tableOffset, bool registerTypes) { ! static const luaL_reg s_funcTable[] = { {"__gc", wxLua_lua_garbageCollect }, *************** *** 412,416 **** {"__newindex", wxLua_lua_setTableFunc } }; ! static const unsigned funcCount = sizeof(funcTable)/sizeof(funcTable[0]); wxLuaState wxlState(wxlState_); --- 599,603 ---- {"__newindex", wxLua_lua_setTableFunc } }; ! static const size_t s_funcCount = sizeof(s_funcTable)/sizeof(s_funcTable[0]); wxLuaState wxlState(wxlState_); *************** *** 420,428 **** m_startTag = wxlState.tnewtag(); - size_t iClass = 0; int iTag = m_startTag; // install the classes, functions and methods ! for (iClass = 0; iClass < m_classCount; ++iClass, iTag = (registerTypes ? wxlState.tnewtag() : iTag + 1)) { --- 607,614 ---- m_startTag = wxlState.tnewtag(); int iTag = m_startTag; // install the classes, functions and methods ! for (size_t iClass = 0; iClass < m_classCount; ++iClass, iTag = (registerTypes ? wxlState.tnewtag() : iTag + 1)) { *************** *** 430,439 **** *pClass->class_tag = iTag; ! for (size_t iFunction = 0; iFunction < funcCount; iFunction++) { ! wxlState.tsettagmethod(iTag, funcTable[iFunction].name, funcTable[iFunction].func, (void *) pClass); } ! for (int iMethod = 0; iMethod < pClass->num_methods; ++iMethod) { WXLUAMETHOD *pMethod = pClass->methods + iMethod; --- 616,626 ---- *pClass->class_tag = iTag; ! for (size_t iFunction = 0; iFunction < s_funcCount; iFunction++) { ! wxlState.tsettagmethod(iTag, s_funcTable[iFunction].name, s_funcTable[iFunction].func, (void *) pClass); } ! int iMethod, method_count = pClass->num_methods; ! for (iMethod = 0; iMethod < method_count; ++iMethod) { WXLUAMETHOD *pMethod = pClass->methods + iMethod; *************** *** 446,449 **** --- 633,637 ---- } } + m_lastTag = iTag; Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** wxlcallb.cpp 25 May 2006 03:55:23 -0000 1.18 --- wxlcallb.cpp 28 Aug 2006 05:26:20 -0000 1.19 *************** *** 23,27 **** #endif // WX_PRECOMP - #include "wxlua/include/internal.h" #include "wxlua/include/wxlcallb.h" --- 23,26 ---- |