From: John L. <jr...@us...> - 2007-06-05 21:07:29
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv30959/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: Fix a number of bugs with the new bindings fix override wxConfig::Get fix looking up overloaded static and non static class member functions fix looking up class member functions overloaded from a base class Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** wxlstate.cpp 31 May 2007 17:18:54 -0000 1.98 --- wxlstate.cpp 5 Jun 2007 21:07:25 -0000 1.99 *************** *** 1849,1852 **** --- 1849,1881 ---- } + const WXLUACLASS* wxLuaState::GetLuaClass(const WXLUAMETHOD* method) const + { + wxLuaBindingList::compatibility_iterator node; + for (node = M_WXLSTATEDATA->m_wxlStateData->m_bindingList.GetFirst(); node; node = node->GetNext() ) + { + wxLuaBinding* binding = node->GetData(); + + const WXLUACLASS *pLuaClass = binding->GetLuaClass(method); + if (pLuaClass) + return pLuaClass; + } + + return NULL; + } + const WXLUACLASS* wxLuaState::GetLuaClass(const WXLUAMETHOD_CFUNC* method_cfunc) const + { + wxLuaBindingList::compatibility_iterator node; + for (node = M_WXLSTATEDATA->m_wxlStateData->m_bindingList.GetFirst(); node; node = node->GetNext() ) + { + wxLuaBinding* binding = node->GetData(); + + const WXLUACLASS *pLuaClass = binding->GetLuaClass(method_cfunc); + if (pLuaClass) + return pLuaClass; + } + + return NULL; + } + const WXLUACLASS* wxLuaState::GetBaseLuaClass(int iClassTag) const { *************** *** 2390,2436 **** } ! WXLUAMETHOD* wxLuaState::GetLuaMethod(const WXLUACLASS *pClass, const char *cpIndex) { ! int i_method, method_count = pClass->methods_n; // find a method in the class, recurse through classes from which this class is derived. for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *pMethod = pClass->methods + i_method; ! if (WXLUA_HASBIT(pMethod->type, WXLUAMETHOD_METHOD | WXLUAMETHOD_GETPROP) ! && (strcmp(pMethod->name, cpIndex) == 0)) { ! return pMethod; } } ! if (pClass->baseclass) ! return GetLuaMethod(pClass->baseclass, cpIndex); return NULL; } ! WXLUAMETHOD* wxLuaState::GetLuaProperty(const WXLUACLASS *pClass, const char *cpIndex, bool isLuaSetProp) { ! wxCHECK_MSG(pClass, NULL, wxT("Invalid WXLUACLASS in wxLuaState::GetLuaProperty")); ! int i_method, method_count = pClass->methods_n; // find a method in the class, recurse through classes from which this class is derived. for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *pMethod = pClass->methods + i_method; if (isLuaSetProp) { ! if (WXLUA_HASBIT(pMethod->type, WXLUAMETHOD_SETPROP) && (strcmp(pMethod->name, cpIndex) == 0)) ! return pMethod; } else { ! if (WXLUA_HASBIT(pMethod->type, WXLUAMETHOD_GETPROP) && (strcmp(pMethod->name, cpIndex) == 0)) ! return pMethod; } } ! if (pClass->baseclass) ! return GetLuaProperty(pClass->baseclass, cpIndex, isLuaSetProp); return NULL; --- 2419,2491 ---- } ! WXLUAMETHOD* wxLuaState::GetLuaMethod(const WXLUACLASS *wxlClass, const char *methodName) { ! int i_method, method_count = wxlClass->methods_n; // find a method in the class, recurse through classes from which this class is derived. for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *wxlMethod = wxlClass->methods + i_method; ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD | WXLUAMETHOD_GETPROP) ! && (strcmp(wxlMethod->name, methodName) == 0)) { ! // 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)) ! { ! WXLUACLASS *baseClass = wxlClass->baseclass; ! WXLUAMETHOD *parentMethod = wxlMethod; ! ! while (baseClass) ! { ! parentMethod->type |= WXLUAMETHOD_OVERLOAD_BASE; ! ! WXLUAMETHOD* baseMethod = GetLuaMethod(baseClass, methodName); ! if (baseMethod) ! { ! parentMethod->basemethod = baseMethod; ! parentMethod = baseMethod; ! ! // we have already checked the base classes below this ! if (WXLUA_HASBIT(baseMethod->type, WXLUAMETHOD_OVERLOAD_BASE)) ! break; ! } ! ! baseClass = baseClass->baseclass; ! } ! } ! ! return wxlMethod; } } ! if (wxlClass->baseclass) ! return GetLuaMethod(wxlClass->baseclass, methodName); return NULL; } ! WXLUAMETHOD* wxLuaState::GetLuaProperty(const WXLUACLASS *wxlClass, const char *propName, bool isLuaSetProp) { ! wxCHECK_MSG(wxlClass, NULL, wxT("Invalid WXLUACLASS in wxLuaState::GetLuaProperty")); ! int i_method, method_count = wxlClass->methods_n; // find a method in the class, recurse through classes from which this class is derived. for (i_method = 0; i_method < method_count; ++i_method) { ! WXLUAMETHOD *wxlMethod = wxlClass->methods + i_method; if (isLuaSetProp) { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_SETPROP) && (strcmp(wxlMethod->name, propName) == 0)) ! return wxlMethod; } else { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_GETPROP) && (strcmp(wxlMethod->name, propName) == 0)) ! return wxlMethod; } } ! if (wxlClass->baseclass) ! return GetLuaProperty(wxlClass->baseclass, propName, isLuaSetProp); return NULL; *************** *** 3214,3289 **** ! wxString wxLuaState::CreateMethodArgTagsMsg(struct WXLUAMETHOD* method) { ! wxCHECK_MSG(method, wxEmptyString, wxT("Invalid method table")); ! wxString fnOverloadList; ! int i, arg, funcs_count = method->funcs_n; ! WXLUAMETHOD_CFUNC* funcs = method->funcs; ! for (i = 0; i < funcs_count; i++) { ! wxString fnOverload = wxString::Format(wxT("%02d. %s("), (i+1), lua2wx(method->name).c_str()); ! for (arg = 0; arg < funcs[i].maxargs; arg++) { ! // optional args? ! if ((funcs[i].minargs < funcs[i].maxargs) && (arg == funcs[i].minargs)) ! { ! fnOverload += wxT("["); ! } ! if (arg > 0) ! fnOverload += wxT(", "); ! int tag = (int)*(funcs[i].argtags[arg]); ! if (tag == s_wxluaarg_String) ! { ! fnOverload += wxT("string"); ! } ! else if (tag == s_wxluaarg_Boolean) ! { ! fnOverload += wxT("boolean"); ! } ! else if (tag == s_wxluaarg_Enumeration) ! { ! fnOverload += wxT("enum"); ! } ! else if (tag == s_wxluaarg_Number) ! { ! fnOverload += wxT("number"); ! } ! else if (tag == s_wxluaarg_LightUserData) ! { ! fnOverload += wxT("lightuserdata"); ! } ! else if (tag == s_wxluaarg_UserData) ! { ! fnOverload += wxT("userdata"); ! } ! else if (tag == s_wxluaarg_LuaTable) ! { ! fnOverload += wxT("luatable"); ! } ! else if (tag == s_wxluaarg_LuaFunction) { ! fnOverload += wxT("luafunction"); } ! else { ! fnOverload += GetLuaTagName(tag); } - } ! // close optional args ! if (funcs[i].minargs < funcs[i].maxargs) ! { ! fnOverload += wxT("]"); ! } ! fnOverload += wxT(")"); ! fnOverloadList += fnOverload + wxT("\n"); } --- 3269,3363 ---- ! wxString wxLuaState::CreateMethodArgTagsMsg(struct WXLUAMETHOD* wxlMethod) { ! wxCHECK_MSG(wxlMethod, wxEmptyString, wxT("Invalid method table")); ! wxString fnOverloadList; ! WXLUAMETHOD* method = wxlMethod; ! while (method) { ! WXLUAMETHOD_CFUNC* funcs = method->funcs; ! int i, arg, funcs_count = wxlMethod->funcs_n; ! int i_func = 0; ! for (i = 0; i < funcs_count; i++) { ! // skip over the overload function ! if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_OVERLOAD)) ! continue; ! i_func++; // only count the non overload functions ! wxString fnOverload = wxString::Format(wxT("%02d. %s("), i_func, lua2wx(method->name).c_str()); ! for (arg = 0; arg < funcs[i].maxargs; arg++) { ! // optional args? ! if ((funcs[i].minargs < funcs[i].maxargs) && (arg == funcs[i].minargs)) ! { ! fnOverload += wxT("["); ! } ! ! if (arg > 0) ! fnOverload += wxT(", "); ! ! int tag = (int)*(funcs[i].argtags[arg]); ! ! if (tag == s_wxluaarg_String) ! { ! fnOverload += wxT("string"); ! } ! else if (tag == s_wxluaarg_Boolean) ! { ! fnOverload += wxT("boolean"); ! } ! else if (tag == s_wxluaarg_Enumeration) ! { ! fnOverload += wxT("enum"); ! } ! else if (tag == s_wxluaarg_Number) ! { ! fnOverload += wxT("number"); ! } ! else if (tag == s_wxluaarg_LightUserData) ! { ! fnOverload += wxT("lightuserdata"); ! } ! else if (tag == s_wxluaarg_UserData) ! { ! fnOverload += wxT("userdata"); ! } ! else if (tag == s_wxluaarg_LuaTable) ! { ! fnOverload += wxT("luatable"); ! } ! else if (tag == s_wxluaarg_LuaFunction) ! { ! fnOverload += wxT("luafunction"); ! } ! else ! { ! fnOverload += GetLuaTagName(tag); ! if ((arg == 0) && !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC)) ! fnOverload += wxT("(self)"); ! } } ! ! // close optional args ! if (funcs[i].minargs < funcs[i].maxargs) { ! fnOverload += wxT("]"); } ! fnOverload += wxT(")"); ! if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC)) ! fnOverload += wxT(" - static"); ! fnOverloadList += fnOverload + wxT("\n"); ! } ! ! method = method->basemethod; } *************** *** 3292,3298 **** // Redirect lua function call to 1 method from a list of overloaded functions ! int LUACALL wxLuaState::CallOverloadedFunction(struct WXLUAMETHOD* overloadedMethods) { ! wxCHECK_MSG(overloadedMethods, 0, wxT("Invalid overloaded method table")); int i, arg; --- 3366,3372 ---- // Redirect lua function call to 1 method from a list of overloaded functions ! int LUACALL wxLuaState::CallOverloadedFunction(struct WXLUAMETHOD* wxlMethod) { ! wxCHECK_MSG(wxlMethod, 0, wxT("Invalid overloaded method table")); int i, arg; *************** *** 3300,3304 **** // do nothing ! if (!overloadedMethods || (overloadedMethods->funcs_n < 1)) return 0; --- 3374,3378 ---- // do nothing ! if (!wxlMethod || (wxlMethod->funcs_n < 1)) return 0; *************** *** 3315,3326 **** } ! // for methods like pen:SetColour(0,0,0) first lua arg is the wxPen (eg. self) ! if (WXLUA_HASBIT(overloadedMethods[0].type, WXLUAMETHOD_METHOD)) ! { ! argCount--; ! lua_argStart++; ! } ! ! #if 0 // prepare overload function table WXLUAMETHOD** overloadFunctionTable = new WXLUAMETHOD*[overloadedMethodCount]; --- 3389,3393 ---- } ! /* // prepare overload function table WXLUAMETHOD** overloadFunctionTable = new WXLUAMETHOD*[overloadedMethodCount]; *************** *** 3355,3370 **** } #endif ! #endif // 0 ! ! int overloadedMethodCount = overloadedMethods->funcs_n; ! WXLUAMETHOD_CFUNC* overloadFunctionTable = overloadedMethods->funcs; // only look at the methods that could possibly work wxArrayPtrVoid funcArray; ! for (i = 0; i < overloadedMethodCount; ++i) { ! if ((argCount >= overloadFunctionTable[i].minargs) && ! (argCount <= overloadFunctionTable[i].maxargs)) ! funcArray.Add(&overloadFunctionTable[i]); } --- 3422,3444 ---- } #endif ! */ // only look at the methods that could possibly work wxArrayPtrVoid funcArray; ! WXLUAMETHOD* method = wxlMethod; ! while (method) { ! for (i = 0; i < method->funcs_n; ++i) ! { ! if (!WXLUA_HASBIT(method->funcs[i].type, WXLUAMETHOD_OVERLOAD) && ! (argCount >= method->funcs[i].minargs) && ! (argCount <= method->funcs[i].maxargs)) ! { ! funcArray.Add(&method->funcs[i]); ! } ! ! } ! ! method = method->basemethod; } *************** *** 3380,3384 **** } ! int ltype = lua_Type(arg+1+lua_argStart); for (i = 0; i < (int)funcArray.GetCount(); i++) --- 3454,3459 ---- } ! int arg_lua = arg+1+lua_argStart; // arg N in lua ! int ltype = lua_Type(arg_lua); for (i = 0; i < (int)funcArray.GetCount(); i++) *************** *** 3387,3392 **** bestFunc = func; // does this method have any more arguments? ! if (!func->argtags || !func->argtags[arg]) { // this one won't work, try the next --- 3462,3469 ---- bestFunc = func; + int arg_wxlua = arg; // arg N in wxLuaArgTag + // does this method have any more arguments? ! if (!func->argtags[arg_wxlua]) { // this one won't work, try the next *************** *** 3396,3402 **** // get argument tag id ! int tag = (int)*(func->argtags[arg]); ! //wxPrintf(wxT("ARG '%s' argCount %d arg %d ltype %d wxtype %d func_count %d, f# %d\n"), lua2wx(overloadedMethods->name).c_str(), argCount, arg, ltype, tag, funcArray.GetCount(), i); if (tag == s_wxluaarg_String) --- 3473,3479 ---- // get argument tag id ! int tag = (int)*(func->argtags[arg_wxlua]); ! //wxPrintf(wxT("ARG '%s' type %d argCount %d arg %d arg_lua %d arg_wxlua %d ltype %d wxtype %d func_count %d/%d\n"), lua2wx(wxlMethod->name).c_str(), func->type, argCount, arg, arg_lua, arg_wxlua, ltype, tag, i, funcArray.GetCount()); if (tag == s_wxluaarg_String) *************** *** 3434,3438 **** else if (tag == s_wxluaarg_LightUserData) { ! if (!lua_IsLightUserData(arg+1+lua_argStart)) { funcArray.RemoveAt(i); i--; --- 3511,3515 ---- else if (tag == s_wxluaarg_LightUserData) { ! if (!lua_IsLightUserData(arg_lua)) { funcArray.RemoveAt(i); i--; *************** *** 3442,3446 **** else if (tag == s_wxluaarg_UserData) { ! if (!lua_IsUserData(arg+1+lua_argStart)) { funcArray.RemoveAt(i); i--; --- 3519,3523 ---- else if (tag == s_wxluaarg_UserData) { ! if (!lua_IsUserData(arg_lua)) { funcArray.RemoveAt(i); i--; *************** *** 3450,3454 **** else if (tag == s_wxluaarg_LuaTable) { ! if (!lua_IsTable(arg+1+lua_argStart)) { funcArray.RemoveAt(i); i--; --- 3527,3531 ---- else if (tag == s_wxluaarg_LuaTable) { ! if (!lua_IsTable(arg_lua)) { funcArray.RemoveAt(i); i--; *************** *** 3458,3462 **** else if (tag == s_wxluaarg_LuaFunction) { ! if (!lua_IsFunction(arg+1+lua_argStart)) { funcArray.RemoveAt(i); i--; --- 3535,3539 ---- else if (tag == s_wxluaarg_LuaFunction) { ! if (!lua_IsFunction(arg_lua)) { funcArray.RemoveAt(i); i--; *************** *** 3464,3468 **** } } ! else if (!IsUserDataType(arg+1+lua_argStart, tag) && (tag != M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL)) // FIXME! { --- 3541,3545 ---- } } ! else if (!IsUserDataType(arg_lua, tag) && (tag != M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL)) // FIXME! { *************** *** 3541,3558 **** wxString fnOverloadList = wxT("wxLua Function Overload Table:\n"); ! fnOverloadList += CreateMethodArgTagsMsg(overloadedMethods); wxString errmsg; ! if (bestFunc == NULL) errmsg = wxString::Format(wxT("wxLua overloaded function %s has invalid argument\n%s"), fnCall.c_str(), fnOverloadList.c_str()); else { ! for (i = 0; i < overloadedMethodCount; i++) { ! if (&overloadFunctionTable[i] == bestFunc) ! break; } ! errmsg = wxString::Format(wxT("wxLua overloaded function %s has invalid argument %d on method %02d\n%s"), fnCall.c_str(), (invalidArg+1), (i+1), fnOverloadList.c_str()); } --- 3618,3642 ---- wxString fnOverloadList = wxT("wxLua Function Overload Table:\n"); ! fnOverloadList += CreateMethodArgTagsMsg(wxlMethod); wxString errmsg; ! if (1) //bestFunc == NULL) FIXME errmsg = wxString::Format(wxT("wxLua overloaded function %s has invalid argument\n%s"), fnCall.c_str(), fnOverloadList.c_str()); else { ! method = wxlMethod; ! while (method) { ! for (i = 0; i < method->funcs_n; ++i) ! { ! if (&method->funcs[i] == bestFunc) ! break; ! } ! ! method = method->basemethod; } ! ! errmsg = wxString::Format(wxT("wxLua overloaded function %s has invalid argument %d on method %02d\n%s"), fnCall.c_str(), (invalidArg), (i+1), fnOverloadList.c_str()); } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** wxlbind.cpp 31 May 2007 17:18:54 -0000 1.61 --- wxlbind.cpp 5 Jun 2007 21:07:25 -0000 1.62 *************** *** 54,62 **** // otherwise the colon notation *must* be used. lua_remove(L, 1); // remove the wxLuaFunction userdata from the stack return (*m_wxlMethod->funcs[0].func)(L); } ! // A function object needs to be deleted because the object is being ! // garbage collected. int LUACALL wxlua_gc_wxLuaFunction(lua_State *L) { --- 54,68 ---- // otherwise the colon notation *must* be used. lua_remove(L, 1); // remove the wxLuaFunction userdata from the stack + + if (m_wxlMethod->basemethod) + { + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(m_wxlMethod); + } + return (*m_wxlMethod->funcs[0].func)(L); } ! // A wxLuaFunction object is being garbage collected. int LUACALL wxlua_gc_wxLuaFunction(lua_State *L) { *************** *** 86,91 **** // remove the userdata *this from the stack ! if (pFunction->m_wxlMethod && WXLUA_HASBIT(pFunction->m_wxlMethod->type, WXLUAMETHOD_STATIC)) ! lua_remove(L, 1); return pFunction->CallMethod(L); --- 92,97 ---- // remove the userdata *this from the stack ! //if (pFunction->m_wxlMethod && WXLUA_HASBIT(pFunction->m_wxlMethod->type, WXLUAMETHOD_STATIC)) ! // lua_remove(L, 1); return pFunction->CallMethod(L); *************** *** 789,794 **** lua_pushstring(L, "__call"); //lua_pushcfunction(L, wxlMethod->func); ! lua_pushlightuserdata(L, &wxlua_checkremovetable); // push the method userdata ! lua_pushcclosure(L, wxlMethod->funcs[0].func, 1); // push func with func as upvalue lua_rawset(L, -3); --- 795,800 ---- lua_pushstring(L, "__call"); //lua_pushcfunction(L, wxlMethod->func); ! lua_pushlightuserdata(L, &wxlua_checkremovetable); // push tag to recognize table call ! lua_pushcclosure(L, wxlMethod->funcs[0].func, 1); // push func with tag as upvalue lua_rawset(L, -3); *************** *** 969,970 **** --- 975,1021 ---- return (luaEvent != NULL) ? lua2wx(luaEvent->name) : wxString(); } + + const WXLUACLASS* wxLuaBinding::GetLuaClass(const WXLUAMETHOD* wxlMethod) const + { + for (size_t i_class = 0; i_class < m_classCount; ++i_class) + { + WXLUACLASS *wxlClass = m_classList + i_class; + int i_method, method_count = wxlClass->methods_n; + + for (i_method = 0; i_method < method_count; ++i_method) + { + for (int i = 0; i < wxlClass[i_method].methods_n; ++i) + { + if (&wxlClass[i_method].methods[i] == wxlMethod) + return wxlClass; + } + } + + } + + return NULL; + } + + const WXLUACLASS* wxLuaBinding::GetLuaClass(const WXLUAMETHOD_CFUNC* wxlMethod_cfunc) const + { + for (size_t i_class = 0; i_class < m_classCount; ++i_class) + { + WXLUACLASS *wxlClass = m_classList + i_class; + int i_method, method_count = wxlClass->methods_n; + + for (i_method = 0; i_method < method_count; ++i_method) + { + for (int i = 0; i < wxlClass[i_method].methods_n; ++i) + { + for (int j = 0; j < wxlClass[i_method].methods[i].funcs_n; ++j) + { + if (&wxlClass[i_method].methods[i].funcs[j] == wxlMethod_cfunc) + return wxlClass; + } + } + } + + } + + return NULL; + } |