From: John L. <jr...@us...> - 2007-06-13 00:09:10
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10172/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: Add new flag for wxLuaBindMethod WXLUAMETHOD_DELETE to know if this is our special delete function. Do not treat the delete function as if it was overloaded from base class Fix MSVC warnings about comparing ints and enums in wxlbind.cpp Add "class" to get class from wxLuaBinding_XXX in lua, also check for null for class_name Add bitlib from Reuben Thomas to wxlstate.cpp, maybe not the best place, but it's small Add code for bindings.wx.lua to check base classes and also functions overloading base class functions Add more unittest.wx.lua code to verify bindings Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -d -r1.108 -r1.109 *** wxlstate.cpp 12 Jun 2007 13:19:37 -0000 1.108 --- wxlstate.cpp 13 Jun 2007 00:09:04 -0000 1.109 *************** *** 1,5 **** ///////////////////////////////////////////////////////////////////////////// // Purpose: wxWidgets interface to lua ! // Author: Ray Gilbert, John Labenski, J Winwood // Created: 14/11/2001 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. --- 1,5 ---- ///////////////////////////////////////////////////////////////////////////// // Purpose: wxWidgets interface to lua ! // Author: Ray Gilbert, John Labenski, J Winwood (Reuben Thomas for bitlib at bottom) // Created: 14/11/2001 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. *************** *** 42,45 **** --- 42,47 ---- wxLuaState wxNullLuaState(false); + LUALIB_API int luaopen_bit (lua_State *L); + // ---------------------------------------------------------------------------- // C functions for lua used in wxLuaState *************** *** 1184,1187 **** --- 1186,1190 ---- // 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 *************** *** 2616,2620 **** wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); - wxLuaObject* wxlObj = NULL; lua_State* L = M_WXLSTATEDATA->m_lua_State; bool found = false; --- 2619,2622 ---- *************** *** 2625,2628 **** --- 2627,2632 ---- if (lua_istable(L, -1)) // else not installed or already removed? Not good in any case. { + wxLuaObject* wxlObj = NULL; + lua_pushlightuserdata(L, (void *)pObject); lua_rawget(L, -2); // pop key, push table or nil *************** *** 2640,2643 **** --- 2644,2655 ---- lua_pop(L, 2); // pop registry table and object table or nil + + if (wxlObj != NULL) + { + if (push_method && wxlObj->GetObject()) + found = true; + else if (!push_method) + found = true; + } } else *************** *** 2648,2659 **** } - if (wxlObj) - { - if (push_method && wxlObj->GetObject()) - found = true; - else if (!push_method) - found = true; - } - return found; } --- 2660,2663 ---- *************** *** 3719,3720 **** --- 3723,3797 ---- { } + + //----------------------------------------------------------------------------- + // bitlib release 21 - Bitwise operations library + // by Reuben Thomas <rr...@sc...> + // http://luaforge.net/projects/bitlib + // copyright Reuben Thomas 2000-2006, and is released under the MIT license + //----------------------------------------------------------------------------- + + // This is the code copied directly from lbitlib.c and ever so slightly modified + // to allow it to work here. + + /* Bitwise operations library */ + /* Reuben Thomas nov00-08dec06 */ + + //#include "lauxlib.h" + //#include "lua.h" + + //#include <inttypes.h> + + //typedef uintmax_t Integer; + //typedef intmax_t UInteger; + + typedef int Integer; // FIXME - is this good enough? probably for us + typedef unsigned int UInteger; + + #define TDYADIC(name, op, type1, type2) \ + static int bit_ ## name(lua_State* L) { \ + lua_pushnumber(L, \ + (type1)luaL_checknumber(L, 1) op (type2)luaL_checknumber(L, 2)); \ + return 1; \ + } + + #define MONADIC(name, op, type) \ + static int bit_ ## name(lua_State* L) { \ + lua_pushnumber(L, op (type)luaL_checknumber(L, 1)); \ + return 1; \ + } + + #define VARIADIC(name, op, type) \ + static int bit_ ## name(lua_State *L) { \ + int n = lua_gettop(L), i; \ + Integer w = (type)luaL_checknumber(L, 1); \ + for (i = 2; i <= n; i++) \ + w op (type)luaL_checknumber(L, i); \ + lua_pushnumber(L, w); \ + return 1; \ + } + + MONADIC(bnot, ~, Integer) + VARIADIC(band, &=, Integer) + VARIADIC(bor, |=, Integer) + VARIADIC(bxor, ^=, Integer) + TDYADIC(lshift, <<, Integer, UInteger) + TDYADIC(rshift, >>, UInteger, UInteger) + TDYADIC(arshift, >>, Integer, UInteger) + TDYADIC(mod, %, Integer, Integer) + + static const struct luaL_reg bitlib[] = { + {"bnot", bit_bnot}, + {"band", bit_band}, + {"bor", bit_bor}, + {"bxor", bit_bxor}, + {"lshift", bit_lshift}, + {"rshift", bit_rshift}, + {"arshift", bit_arshift}, + {"mod", bit_mod}, + {NULL, NULL} + }; + + LUALIB_API int luaopen_bit (lua_State *L) { + luaL_openlib(L, "bit", bitlib, 0); + return 1; + } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** wxlbind.cpp 12 Jun 2007 13:19:37 -0000 1.72 --- wxlbind.cpp 13 Jun 2007 00:09:04 -0000 1.73 *************** *** 348,351 **** --- 348,354 ---- found = true; lua_remove(L, 2); // remove the name of the function + if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_STATIC)) + lua_remove(L, 1); // remove the userdata + result = (*wxlMethod->funcs[0].func)(L); } *************** *** 476,482 **** int t1 = 0xFF & ((const wxLuaBindMethod*)p1)->type; int t2 = 0xFF & ((const wxLuaBindMethod*)p2)->type; ! int t12 = (t1 & t2); if ((t12 == WXLUAMETHOD_METHOD) || (t12 == WXLUAMETHOD_GETPROP) || ! (t12 == WXLUAMETHOD_METHOD|WXLUAMETHOD_GETPROP)) return 0; --- 479,485 ---- int t1 = 0xFF & ((const wxLuaBindMethod*)p1)->type; int t2 = 0xFF & ((const wxLuaBindMethod*)p2)->type; ! int t12 = int(t1) & int(t2); if ((t12 == WXLUAMETHOD_METHOD) || (t12 == WXLUAMETHOD_GETPROP) || ! (t12 == (int(WXLUAMETHOD_METHOD)|int(WXLUAMETHOD_GETPROP)))) return 0; *************** *** 522,533 **** { // Sort all the bindings by something useful if (m_classArray && (m_classCount > 0)) { qsort(m_classArray, m_classCount, sizeof(wxLuaBindClass), wxLuaBindClassArrayCompareFn); ! wxLuaBindClass* wxlClass = m_classArray; for (size_t i = 0; i < m_classCount; ++i, ++wxlClass) { qsort(wxlClass->methods, wxlClass->methods_n, sizeof(wxLuaBindMethod), wxLuaBindMethodArrayCompareFnInit); } } --- 525,541 ---- { // Sort all the bindings by something useful + if (m_classArray && (m_classCount > 0)) { qsort(m_classArray, m_classCount, sizeof(wxLuaBindClass), wxLuaBindClassArrayCompareFn); ! wxLuaBindClass* wxlClass = m_classArray; for (size_t i = 0; i < m_classCount; ++i, ++wxlClass) { + // Also sort the member functions for each class qsort(wxlClass->methods, wxlClass->methods_n, sizeof(wxLuaBindMethod), wxLuaBindMethodArrayCompareFnInit); + // And their enums + if (wxlClass->enums && (wxlClass->enums_n > 0)) + qsort(wxlClass->enums, wxlClass->enums_n, sizeof(wxLuaBindDefine), wxLuaBindDefineArrayCompareFn); } } *************** *** 1038,1042 **** // iterate through the base classes to find if this function is // an overload, but only if we haven't checked already. ! if (!WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_OVERLOAD_BASE)) { wxLuaBindClass *baseClass = wxlClass->baseclass; --- 1046,1050 ---- // iterate through the base classes to find if this function is // an overload, but only if we haven't checked already. ! if (!WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_OVERLOAD_BASE|WXLUAMETHOD_DELETE)) { wxLuaBindClass *baseClass = wxlClass->baseclass; *************** *** 1054,1058 **** // we have already checked the base classes below this ! if (WXLUA_HASBIT(baseMethod->type, WXLUAMETHOD_OVERLOAD_BASE)) break; } --- 1062,1066 ---- // we have already checked the base classes below this ! if (WXLUA_HASBIT(baseMethod->type, WXLUAMETHOD_OVERLOAD_BASE|WXLUAMETHOD_DELETE)) break; } *************** *** 1061,1064 **** --- 1069,1073 ---- } } + return wxlMethod; } *************** *** 1101,1104 **** --- 1110,1114 ---- // wxluabind_wxLuaBindCFunc_index //----------------------------------------------------------------------------- + int LUACALL wxluabind_wxLuaBindClass_index(lua_State* L); int LUACALL wxluabind_wxLuaBindCFunc_index(lua_State* L) *************** *** 1151,1158 **** return 1; } else if (strcmp(idx_str, "class_name") == 0) { ! lua_pushstring(L, wxlBinding->GetLuaClass(wxlCFunc)->name); ! return 1; } } --- 1161,1189 ---- return 1; } + else if (strcmp(idx_str, "class") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlCFunc); + if (c != NULL) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = c; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass_index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + } else if (strcmp(idx_str, "class_name") == 0) { ! const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlCFunc); ! if (c != NULL) ! { ! lua_pushstring(L, c->name); ! return 1; ! } } } *************** *** 1235,1242 **** return 0; } else if (strcmp(idx_str, "class_name") == 0) { ! lua_pushstring(L, wxlBinding->GetLuaClass(wxlMethod)->name); ! return 1; } } --- 1266,1294 ---- return 0; } + else if (strcmp(idx_str, "class") == 0) + { + const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlMethod); + if (c != NULL) + { + const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); + *ptr = c; + lua_newtable(L); + lua_pushstring(L, "__index"); + lua_pushlightuserdata(L, wxlBinding); + lua_pushcclosure(L, wxluabind_wxLuaBindClass_index, 1); // push func with tag as upvalue + lua_rawset(L, -3); + lua_setmetatable(L, -2); + + return 1; + } + } else if (strcmp(idx_str, "class_name") == 0) { ! const wxLuaBindClass* c = wxlBinding->GetLuaClass(wxlMethod); ! if (c != NULL) ! { ! lua_pushstring(L, c->name); ! return 1; ! } } } |