From: John L. <jr...@us...> - 2008-01-08 16:11:21
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv18563/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp Log Message: Fix static %member variables and give clearer messages about errors in wxLua udata metatable functions Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.113 retrieving revision 1.114 diff -C2 -d -r1.113 -r1.114 *** wxlbind.cpp 8 Jan 2008 06:19:53 -0000 1.113 --- wxlbind.cpp 8 Jan 2008 16:11:15 -0000 1.114 *************** *** 347,351 **** int result = 0; wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); void *obj_ptr = wxlua_touserdata(L, 1, false); --- 347,351 ---- int result = 0; wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); // fail hard void *obj_ptr = wxlua_touserdata(L, 1, false); *************** *** 355,362 **** { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call a class method using '%s' on a '%s' type."), wxlua_luaL_typename(L, 2).c_str(), lua2wx(wxlClass->name).c_str())); } ! else if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_type(L, 1) == *wxlClass->wxluatype)) { // check if we're to call the baseclass function or if it's a Lua derived function --- 355,362 ---- { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call a class method using '%s' on a '%s' wxLua type."), wxlua_luaL_typename(L, 2).c_str(), lua2wx(wxlClass->name).c_str())); } ! else if (wxluaT_type(L, 1) == *wxlClass->wxluatype) { // check if we're to call the baseclass function or if it's a Lua derived function *************** *** 385,390 **** { found = true; ! lua_remove(L, 2); // remove the name of the function ! result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); // } else --- 385,394 ---- { found = true; ! if (WXLUA_HASBIT(wxlMethod->method_type, WXLUAMETHOD_STATIC)) ! lua_pop(L, 2); // remove the userdata and func name ! else ! lua_pop(L, 1); // remove the name of the function ! ! result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } else *************** *** 418,424 **** { found = true; - lua_remove(L, 2); // remove the name of the function if (WXLUA_HASBIT(wxlMethod->method_type, WXLUAMETHOD_STATIC)) ! lua_remove(L, 1); // remove the userdata result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); --- 422,429 ---- { found = true; if (WXLUA_HASBIT(wxlMethod->method_type, WXLUAMETHOD_STATIC)) ! lua_pop(L, 2); // remove the userdata and func name ! else ! lua_pop(L, 1); // remove the name of the function result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); *************** *** 433,437 **** if (!found) { ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call an unknown method '%s' on a '%s' type."), lua2wx(name).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } --- 438,442 ---- if (!found) { ! wxlua_error(L, wxString::Format(_("wxLua: Unable to call an unknown method '%s' on a '%s' type."), lua2wx(name).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } *************** *** 447,451 **** { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); // Lua Stack: 1 = userdata, 2 = key, 3 = value; userdata.key = value --- 452,456 ---- { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); // fail hard // Lua Stack: 1 = userdata, 2 = key, 3 = value; userdata.key = value *************** *** 457,464 **** { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call a class method using '%s' on a '%s' type."), wxlua_luaL_typename(L, 2).c_str(), lua2wx(wxlClass->name).c_str())); } ! else if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_type(L, 1) == *wxlClass->wxluatype)) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods --- 462,469 ---- { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call or add a class method using '%s' on a '%s' type."), wxlua_luaL_typename(L, 2).c_str(), lua2wx(wxlClass->name).c_str())); } ! else if (wxluaT_type(L, 1) == *wxlClass->wxluatype) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods *************** *** 468,472 **** { found = true; ! lua_remove(L, 2); (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } --- 473,480 ---- { found = true; ! lua_remove(L, 2); // remove the function name ! if (WXLUA_HASBIT(wxlMethod->method_type, WXLUAMETHOD_STATIC)) ! lua_remove(L, 1); // remove the userdata too, leaving the value ! (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } *************** *** 485,489 **** { found = true; ! lua_remove(L, 2); (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } --- 493,500 ---- { found = true; ! lua_remove(L, 2); // remove the function name ! if (WXLUA_HASBIT(wxlMethod->method_type, WXLUAMETHOD_STATIC)) ! lua_remove(L, 1); // remove the userdata too, leaving the value ! (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } *************** *** 493,505 **** if (!found) { wxLuaState wxlState(L); wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! void *pObject = wxlua_touserdata(L, 1, false); wxLuaObject* wxlObj = new wxLuaObject(wxlState, 3); ! wxlua_setderivedmethod(L, pObject, name, wxlObj); } } return 0; } --- 504,523 ---- if (!found) { + found = true; wxLuaState wxlState(L); wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! void *obj_ptr = wxlua_touserdata(L, 1, false); wxLuaObject* wxlObj = new wxLuaObject(wxlState, 3); ! wxlua_setderivedmethod(L, obj_ptr, name, wxlObj); } } + if (!found) + { + wxlua_error(L, wxString::Format(_("wxLua: Unable to call or add an unknown method '%s' on a '%s' type."), + lua2wx(name).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); + } + return 0; } *************** *** 541,548 **** int LUACALL wxlua_wxLuaBindMethod_table__index(lua_State *L) { ! // 1 = table, 2 = key wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); int result = 0; --- 559,566 ---- int LUACALL wxlua_wxLuaBindMethod_table__index(lua_State *L) { ! // Lua stack: 1 = table, 2 = key wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! wxCHECK_MSG(wxlClass, 0, wxT("Invalid wxLuaBindClass")); // fail hard int result = 0; *************** *** 562,575 **** { lua_pop(L, 2); // remove the table and the name of the function ! result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); // } else { ! lua_pushvalue(L, -1); ! lua_rawget(L, -3); ! if (lua_isnil(L, -1)) ! lua_pop(L, 1); ! else ! result = 1; } --- 580,590 ---- { lua_pop(L, 2); // remove the table and the name of the function ! result = (*wxlMethod->wxluacfuncs[0].lua_cfunc)(L); } else { ! lua_pushvalue(L, -1); // copy key ! lua_rawget(L, -3); // get t[key] = value, pops key pushes value ! result = 1; // ok if nil } *************** *** 603,609 **** else { ! lua_pushvalue(L, -2); ! lua_pushvalue(L, -2); ! lua_rawset(L, -5); } --- 618,624 ---- else { ! lua_pushvalue(L, -2); // copy key ! lua_pushvalue(L, -2); // copy value ! lua_rawset(L, -5); // set t[key] = value, pops key and value } |