From: John L. <jr...@us...> - 2007-07-16 19:36:09
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15684/wxLua/modules/wxlua/src Modified Files: Makefile wxlstate.cpp wxlua_bind.cpp Log Message: Separate wxWidgets bindings into wxadv, wxaui, wxbase, wxcore, etc... Allow bool = 1/0 and 1/0 = bool in wxlua_getboolean/integer/number Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** wxlstate.cpp 28 Jun 2007 22:45:57 -0000 1.119 --- wxlstate.cpp 16 Jul 2007 19:35:30 -0000 1.120 *************** *** 353,357 **** // pop the table and set it as the metatable for the newuserdata if (lua_setmetatable(L, -2) != 0) ! { wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) --- 353,357 ---- // pop the table and set it as the metatable for the newuserdata if (lua_setmetatable(L, -2) != 0) ! { wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) *************** *** 740,744 **** bool LUACALL wxlua_getbooleantype(lua_State *L, int stack_idx) { ! if (!wxlua_isbooleantype(L, stack_idx)) { wxString msg(wxString::Format(_("wxLua: Expected a boolean for parameter %d, but got '%s'."), --- 740,746 ---- bool LUACALL wxlua_getbooleantype(lua_State *L, int stack_idx) { ! int l_type = lua_type(L, stack_idx); ! ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Boolean)) { wxString msg(wxString::Format(_("wxLua: Expected a boolean for parameter %d, but got '%s'."), *************** *** 747,763 **** } ! int num = (int)lua_toboolean(L, stack_idx); ! ! // 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.", stack_idx)); ! return num ? true : false; } long LUACALL wxlua_getintegertype(lua_State *L, int stack_idx) { ! if (!wxlua_isintegertype(L, stack_idx)) { wxString msg(wxString::Format(_("wxLua: Expected an integer for parameter %d, but got '%s'."), --- 749,766 ---- } ! double num = 0; ! // we also allow 0 = false and !0 = true (Lua thinks 0 == true, i.e. !nil) ! if (l_type == LUA_TNUMBER) ! num = (double)lua_tonumber(L, stack_idx); ! else ! num = (double)lua_toboolean(L, stack_idx); ! return (num != 0); } long LUACALL wxlua_getintegertype(lua_State *L, int stack_idx) { ! int l_type = lua_type(L, stack_idx); ! ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Integer)) { wxString msg(wxString::Format(_("wxLua: Expected an integer for parameter %d, but got '%s'."), *************** *** 766,770 **** } ! double value = lua_tonumber(L, stack_idx); if (value != (long)value) --- 769,778 ---- } ! double value = 0; ! // we also allow bool = 1/0 which Lua evaluates to nil ! if (l_type == LUA_TBOOLEAN) ! value = lua_toboolean(L, stack_idx) ? 1 : 0; ! else ! value = lua_tonumber(L, stack_idx); if (value != (long)value) *************** *** 779,783 **** double LUACALL wxlua_getnumbertype(lua_State *L, int stack_idx) { ! if (!wxlua_isnumbertype(L, stack_idx)) { wxString msg(wxString::Format(_("wxLua: Expected a number for parameter %d, but got '%s'."), --- 787,793 ---- double LUACALL wxlua_getnumbertype(lua_State *L, int stack_idx) { ! int l_type = lua_type(L, stack_idx); ! ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Number)) { wxString msg(wxString::Format(_("wxLua: Expected a number for parameter %d, but got '%s'."), *************** *** 786,790 **** } ! return lua_tonumber(L, stack_idx); } --- 796,807 ---- } ! double value = 0; ! // we also allow bool = 1/0 which Lua evaluates to nil ! if (l_type == LUA_TBOOLEAN) ! value = lua_toboolean(L, stack_idx) ? 1 : 0; ! else ! value = lua_tonumber(L, stack_idx); ! ! return value; } Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/Makefile,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile 4 Jul 2007 05:39:21 -0000 1.15 --- Makefile 16 Jul 2007 19:35:30 -0000 1.16 *************** *** 18,28 **** # ---------------------------------------------------------------------------- ! TARGET_LIBNAME = lib$(WXLUA_LIB) ! TARGET_LIBDIR = $(WXLUA_LIBDIR) ! ! TARGET_LIB_STATIC = $(TARGET_LIBDIR)/$(TARGET_LIBNAME).a ! TARGET_LIB_SHARED = $(TARGET_LIBDIR)/$(TARGET_LIBNAME).so.$(WXLUA_LIBVERSION_CURRENT).$(WXLUA_LIBVERSION_REVISION).$(WXLUA_LIBVERSION_AGE) ! TARGET_LIB_LINK1 = $(TARGET_LIBNAME).so.$(WXLUA_LIBVERSION_CURRENT) ! TARGET_LIB_LINK2 = $(TARGET_LIBNAME).so # ---------------------------------------------------------------------------- --- 18,22 ---- # ---------------------------------------------------------------------------- ! WXLUA_TARGET_LIBNAME = lib$(WXLUA_LIB) # ---------------------------------------------------------------------------- *************** *** 50,72 **** $(CXX) -c $(CXXFLAGS) $(APPEXTRADEFS) -o $@ $< ! all: $(TARGET_LIB_STATIC) $(TARGET_LIB_SHARED) ! ! $(TARGET_LIB_STATIC) : $(OBJECTS) ! @$(RM) $@ ! $(AR) $(AROPTIONS) $@ $(OBJECTS) ! $(RANLIB) $@ ! ! $(TARGET_LIB_SHARED): $(OBJECTS) ! $(CXX) -shared -o $@ $(OBJECTS) $(LIBEXTRALIBS) ! cd $(TARGET_LIBDIR) \ ! && $(RM) $(TARGET_LIB_LINK1) $(TARGET_LIB_LINK2) \ ! && $(LN_S) $(TARGET_LIB_SHARED) $(TARGET_LIB_LINK1) \ ! && $(LN_S) $(TARGET_LIB_SHARED) $(TARGET_LIB_LINK2) ! clean: ! rm -f core $(OBJECTS) $(DEPFILES) \ ! $(TARGET_LIB_STATIC) $(TARGET_LIB_SHARED) \ ! $(TARGET_LIBDIR)/$(TARGET_LIB_LINK1) \ ! $(TARGET_LIBDIR)/$(TARGET_LIB_LINK2) # ---------------------------------------------------------------------------- --- 44,50 ---- $(CXX) -c $(CXXFLAGS) $(APPEXTRADEFS) -o $@ $< ! all: $(WXLUA_TARGET_LIB_STATIC) $(WXLUA_TARGET_LIB_SHARED) ! clean: cleanlib # ---------------------------------------------------------------------------- Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** wxlua_bind.cpp 30 Jun 2007 00:12:26 -0000 1.6 --- wxlua_bind.cpp 16 Jul 2007 19:35:30 -0000 1.7 *************** *** 84,87 **** --- 84,91 ---- { "wxLUAOBJECT_NONE", wxLUAOBJECT_NONE }, { "wxLUAOBJECT_STRING", wxLUAOBJECT_STRING }, + { "wxLUA_MAJOR_VERSION", wxLUA_MAJOR_VERSION }, + { "wxLUA_MINOR_VERSION", wxLUA_MINOR_VERSION }, + { "wxLUA_RELEASE_NUMBER", wxLUA_RELEASE_NUMBER }, + { "wxLUA_SUBRELEASE_NUMBER", wxLUA_SUBRELEASE_NUMBER }, { 0, 0 }, *************** *** 100,103 **** --- 104,108 ---- static wxLuaBindString stringList[] = { + { "wxLUA_VERSION_STRING", wxLUA_VERSION_STRING }, { 0, 0 }, *************** *** 166,181 **** wxLuaBinding* binding = node->GetData(); - lua_createtable(L, 3, 0); // sub table item for each binding - - lua_pushstring(L, "name"); - lua_pushstring(L, wx2lua(binding->GetBindingName())); - lua_rawset(L, -3); - - lua_pushstring(L, "namespace"); - lua_pushstring(L, wx2lua(binding->GetLuaNamespace())); - lua_rawset(L, -3); - // Push function to access the binding info - lua_pushstring(L, "binding"); const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); *ptr = binding; --- 171,175 ---- *************** *** 191,195 **** lua_setmetatable(L, -2); - lua_rawset(L, -3); lua_rawseti(L, -2, idx); --- 185,188 ---- *************** *** 910,913 **** --- 903,948 ---- static wxLuaBindCFunc s_wxluafunc_wxLua_function_typename[1] = {{ wxLua_function_typename, WXLUAMETHOD_CFUNCTION, 1, 1, s_wxluatagArray_wxLua_function_typename }}; + static wxLuaArgTag s_wxluatagArray_wxLua_function_wxLUA_CHECK_VERSION[] = { &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, NULL }; + // %function bool wxLUA_CHECK_VERSION(int major, int minor, int release) // actually a define + static int LUACALL wxLua_function_wxLUA_CHECK_VERSION(lua_State *L) + { + bool returns; + // int release + int release = (int)wxlua_getnumbertype(L, 3); + // int minor + int minor = (int)wxlua_getnumbertype(L, 2); + // int major + int major = (int)wxlua_getnumbertype(L, 1); + // call wxLUA_CHECK_VERSION + returns = (wxLUA_CHECK_VERSION(major, minor, release)); + // push the result flag + lua_pushboolean(L, returns); + + return 1; + } + static wxLuaBindCFunc s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION[1] = {{ wxLua_function_wxLUA_CHECK_VERSION, WXLUAMETHOD_CFUNCTION, 3, 3, s_wxluatagArray_wxLua_function_wxLUA_CHECK_VERSION }}; + + static wxLuaArgTag s_wxluatagArray_wxLua_function_wxLUA_CHECK_VERSION_FULL[] = { &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, NULL }; + // %function bool wxLUA_CHECK_VERSION_FULL(int major, int minor, int release, int subrel) // actually a define + static int LUACALL wxLua_function_wxLUA_CHECK_VERSION_FULL(lua_State *L) + { + bool returns; + // int subrel + int subrel = (int)wxlua_getnumbertype(L, 4); + // int release + int release = (int)wxlua_getnumbertype(L, 3); + // int minor + int minor = (int)wxlua_getnumbertype(L, 2); + // int major + int major = (int)wxlua_getnumbertype(L, 1); + // call wxLUA_CHECK_VERSION_FULL + returns = (wxLUA_CHECK_VERSION_FULL(major, minor, release, subrel)); + // push the result flag + lua_pushboolean(L, returns); + + return 1; + } + static wxLuaBindCFunc s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION_FULL[1] = {{ wxLua_function_wxLUA_CHECK_VERSION_FULL, WXLUAMETHOD_CFUNCTION, 4, 4, s_wxluatagArray_wxLua_function_wxLUA_CHECK_VERSION_FULL }}; + // --------------------------------------------------------------------------- // wxLuaGetFunctionList_wxlua() is called to register global functions *************** *** 927,930 **** --- 962,967 ---- { "type", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_type, 1, NULL }, { "typename", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_typename, 1, NULL }, + { "wxLUA_CHECK_VERSION", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION, 1, NULL }, + { "wxLUA_CHECK_VERSION_FULL", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION_FULL, 1, NULL }, { 0, 0, 0, 0 }, *************** *** 1012,1018 **** { static wxLuaBinding_wxlua m_binding; ! wxLuaBindingList::compatibility_iterator node = wxLuaBinding::GetBindingList()->Find(&m_binding); ! if (node && (node->GetData() == &m_binding)) ! return false; wxLuaBinding::GetBindingList()->Append(&m_binding); --- 1049,1053 ---- { static wxLuaBinding_wxlua m_binding; ! if (wxLuaBinding::GetBindingList()->Find(&m_binding)) return false; wxLuaBinding::GetBindingList()->Append(&m_binding); |