From: John L. <jr...@us...> - 2007-06-06 18:03:54
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv2918/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: Fix %property generation on the fly Remove remaining extra code in wxLuaState::CallOverloadedFunction Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** wxlstate.cpp 6 Jun 2007 15:20:16 -0000 1.101 --- wxlstate.cpp 6 Jun 2007 18:03:48 -0000 1.102 *************** *** 50,70 **** wxLuaState wxNullLuaState(false); - wxString wxLua_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; - } - // ---------------------------------------------------------------------------- // C functions for lua used in wxLuaState --- 50,53 ---- *************** *** 553,557 **** } ! return wxT("unknown"); } --- 536,540 ---- } ! return wxEmptyString; } *************** *** 2407,2410 **** --- 2390,2396 ---- wxCHECK_MSG(Ok(), wxEmptyString, wxT("Invalid wxLuaState")); + if (tag <= 0) + return wxlua_getwxluatypename(tag); + if (tag == M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL) return wxT("NULL"); *************** *** 3274,3280 **** wxCHECK_MSG(wxlMethod, overloadMethodArray, wxT("Invalid method table")); WXLUAMETHOD* method = wxlMethod; - int i_func = 0; while (method) { --- 3260,3267 ---- wxCHECK_MSG(wxlMethod, overloadMethodArray, wxT("Invalid method table")); + int i_func = 0; // count total number of overloads WXLUAMETHOD* method = wxlMethod; + // traverse the methods down the baseclass methods if any while (method) { *************** *** 3289,3293 **** for (i = 0; i < funcs_count; i++) { ! i_func++; // only count the non overload functions wxString fnOverload = wxString::Format(wxT("%02d. %s%s("), i_func, className.c_str(), lua2wx(method->name).c_str()); --- 3276,3280 ---- for (i = 0; i < funcs_count; i++) { ! i_func++; wxString fnOverload = wxString::Format(wxT("%02d. %s%s("), i_func, className.c_str(), lua2wx(method->name).c_str()); *************** *** 3296,3300 **** if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_OVERLOAD)) { ! // we do print that there is an overload so that in CallOverloadedFunction // we can find what function we were closest too. fnOverload += wxT(" ... ) - overloaded function"); --- 3283,3287 ---- if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_OVERLOAD)) { ! // However, we do print that there is an overload so that in CallOverloadedFunction // we can find what function we were closest too. fnOverload += wxT(" ... ) - overloaded function"); *************** *** 3313,3329 **** int tag = (int)*(funcs[i].argtags[arg]); ! if (tag < 0) ! { ! fnOverload += wxlua_getwxluatypename(tag); ! } ! else ! { ! fnOverload += GetLuaTagName(tag); ! if ((arg == 0) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CONSTRUCTOR) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CFUNCTION)) ! fnOverload += wxT("(self)"); ! } } --- 3300,3310 ---- int tag = (int)*(funcs[i].argtags[arg]); ! fnOverload += GetLuaTagName(tag); ! ! if ((arg == 0) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CONSTRUCTOR) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CFUNCTION)) ! fnOverload += wxT("(self)"); } *************** *** 3352,3364 **** wxCHECK_MSG(wxlMethod, 0, wxT("Invalid overloaded method table")); ! int i, arg; ! int invalidArg = -1; ! ! // do nothing ! if (!wxlMethod || (wxlMethod->funcs_n < 1)) ! return 0; ! bool remove_table = wxlua_removetableforcall(GetLuaState(), true); // get number of arguments called from lua int argCount = lua_GetTop(); --- 3333,3342 ---- wxCHECK_MSG(wxlMethod, 0, wxT("Invalid overloaded method table")); ! // don't remove the table, but do skip past it when counting args bool remove_table = wxlua_removetableforcall(GetLuaState(), true); + int i, arg; + int invalidArg = 0; + // get number of arguments called from lua int argCount = lua_GetTop(); *************** *** 3371,3410 **** } ! /* ! // prepare overload function table ! WXLUAMETHOD** overloadFunctionTable = new WXLUAMETHOD*[overloadedMethodCount]; ! for (i = 0; i < overloadedMethodCount; i++) ! { ! if ((maxargs == -1) || (maxargs < *overloadedMethods[i].args[1])) ! maxargs = *overloadedMethods[i].args[1]; ! ! if ((minargs == -1) || (minargs > *overloadedMethods[i].args[0])) ! minargs = *overloadedMethods[i].args[0]; ! ! overloadFunctionTable[i] = (overloadedMethods+i); ! } ! ! #if !defined(WXLUA_OVERLOAD_SORTED) ! // sort overload on the fly to get proper function selection ! // order by minargs DESC, maxargs DESC ! for (i = 0; i < overloadedMethodCount; i++) ! { ! for (j = i + 1; j < overloadedMethodCount; j++) ! { ! if ((*overloadFunctionTable[j]->args[0] > *overloadFunctionTable[i]->args[0]) || ! (*overloadFunctionTable[j]->args[0] == *overloadFunctionTable[i]->args[0]) && ! (*overloadFunctionTable[j]->args[1] > *overloadFunctionTable[i]->args[1])) ! { ! // swap order ! WXLUAMETHOD* swap = overloadFunctionTable[i]; ! overloadFunctionTable[i] = overloadFunctionTable[j]; ! overloadFunctionTable[j] = swap; ! } ! } ! } ! #endif ! */ ! ! // only look at the methods that could possibly work wxArrayPtrVoid funcArray; WXLUAMETHOD* method = wxlMethod; --- 3349,3353 ---- } ! // only look at the methods that could possibly work and traverse base classes wxArrayPtrVoid funcArray; WXLUAMETHOD* method = wxlMethod; *************** *** 3428,3439 **** // Look at the available functions in parallel, per arg ! for (arg = 0; arg < argCount; arg++) { - if (funcArray.GetCount() == 0u) - { - arg--; - break; - } - int arg_lua = arg+1+lua_argStart; // arg N in lua int ltype = lua_Type(arg_lua); --- 3371,3376 ---- // Look at the available functions in parallel, per arg ! for (arg = 0; (arg < argCount) && (funcArray.GetCount() != 0); arg++) { int arg_lua = arg+1+lua_argStart; // arg N in lua int ltype = lua_Type(arg_lua); *************** *** 3443,3446 **** --- 3380,3384 ---- WXLUAMETHOD_CFUNC* func = (WXLUAMETHOD_CFUNC*)funcArray[i]; bestFunc = func; + invalidArg = arg; int arg_wxlua = arg; // arg N in wxLuaArgTag *************** *** 3449,3453 **** if (!func->argtags[arg_wxlua]) { - // this one won't work, try the next funcArray.RemoveAt(i); i--; --- 3387,3390 ---- *************** *** 3462,3465 **** --- 3399,3403 ---- // Does the lua type match the wxlua arg tag type int is_ok = wxlua_iswxluatype(ltype, tag); + // unknown standard wxlua arg type, check binding tag if (is_ok == -1) *************** *** 3480,3483 **** --- 3418,3423 ---- // If there was a function that matched run it, if > 1 ??? + // Note that the top function is the one that is highest in the + // derived functions from any baseclasses and should be the best choice. if (funcArray.GetCount() > 0) { *************** *** 3488,3504 **** } - if (invalidArg < arg) - invalidArg = arg; - - lua_Debug ar; lua_GetStack(0, &ar); lua_GetInfo("n", &ar); - wxString name = lua2wx(ar.name); - // // Build an error message - // wxString fnCall = name + wxT("("); for (arg = 0; arg < argCount; arg++) --- 3428,3437 ---- *************** *** 3509,3544 **** int ltype = lua_Type(arg+1+lua_argStart); ! if (ltype == LUA_TBOOLEAN) ! { ! fnCall += wxT("boolean"); ! } ! else if (ltype == LUA_TNUMBER) ! { ! fnCall += wxT("number"); ! } ! else if (ltype == LUA_TSTRING) ! { ! fnCall += wxT("string"); ! } ! else if (ltype == LUA_TNIL) ! { ! fnCall += wxT("nil"); ! } ! else if (ltype == LUA_TNONE) ! { ! fnCall += wxT("none"); ! } ! else if (lua_IsTable(arg+1+lua_argStart)) ! { ! fnCall += wxT("luatable"); ! } ! else if (lua_IsLightUserData(arg+1+lua_argStart)) { ! fnCall += wxT("lightuserdata"); ! } else { int tag = ttag(arg+1+lua_argStart); - fnCall += GetLuaTagName(tag); } --- 3442,3452 ---- int ltype = lua_Type(arg+1+lua_argStart); ! if (ltype != LUA_TUSERDATA) { ! fnCall += lua_TypeName(ltype); ! } else { int tag = ttag(arg+1+lua_argStart); fnCall += GetLuaTagName(tag); } *************** *** 3552,3556 **** fnOverloadList += overloadMethodArray[i] + wxT("\n"); - wxString errmsg; --- 3460,3463 ---- *************** *** 3564,3570 **** else { method = wxlMethod; int i_func = 0; ! while (method) { for (i = 0; i < method->funcs_n; ++i) --- 3471,3479 ---- else { + // we have to count the methods that are displayed to find the one that failed method = wxlMethod; int i_func = 0; ! bool found = false; ! while (method && !found) { for (i = 0; i < method->funcs_n; ++i) *************** *** 3572,3576 **** --- 3481,3488 ---- i_func++; if (&method->funcs[i] == bestFunc) + { + found = true; break; + } } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** wxlbind.cpp 6 Jun 2007 03:53:40 -0000 1.63 --- wxlbind.cpp 6 Jun 2007 18:03:48 -0000 1.64 *************** *** 415,419 **** wxlMethod = wxlState.GetLuaMethod(wxlClass, str); ! if ((wxlMethod != NULL) && (wxlMethod->type == WXLUAMETHOD_METHOD)) //wxlMethod->funcs && (wxlMethod->funcs->minargs == 0) && //(wxlMethod->funcs->maxargs == 0)) --- 415,420 ---- wxlMethod = wxlState.GetLuaMethod(wxlClass, str); ! ! if ((wxlMethod != NULL) && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD)) //wxlMethod->funcs && (wxlMethod->funcs->minargs == 0) && //(wxlMethod->funcs->maxargs == 0)) *************** *** 486,490 **** wxlMethod = wxlState.GetLuaMethod(wxlClass, str); ! if ((wxlMethod != NULL) && (wxlMethod->type == WXLUAMETHOD_METHOD)) { found = true; --- 487,491 ---- wxlMethod = wxlState.GetLuaMethod(wxlClass, str); ! if ((wxlMethod != NULL) && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD)) { found = true; |