From: John L. <jr...@us...> - 2007-12-20 02:27:02
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8597/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxldefs.h wxlstate.h wxlua_bind.h Log Message: - Removed wxluabind_removetableforcall(L) used in the bindings to determine if the function was called from the tables used for class constructors. It makes more sense to call an intermediatary function to remove the table before calling the real function. - Removed the wxLuaFunction class since we no longer need it. It was a userdata with a __call metatable to call the real function we want. We now push the actual function or an overload function helper with the wxLuaBindMethod struct as an upvalue to give better error messages. The new way should be faster since it doesn't generate as much garbage. - Added wxlua_argerror(L, stack_idx, type_str) to give a far more informative message from the bindings when the wrong type is an arg to a function. - Renamed WXLUAARG_XXX to WXLUA_TXXX to match LUA_TXXX. * Do not create a separate overload function in the bindings since we can just as easily check for multiple functions using the wxLuaBindMethod and call the generic overload function or just the single function. Index: wxldefs.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxldefs.h,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** wxldefs.h 18 Dec 2007 01:03:34 -0000 1.38 --- wxldefs.h 20 Dec 2007 02:26:57 -0000 1.39 *************** *** 67,71 **** //----------------------------------------------------------------------------- ! #define WXLUA_BINDING_VERSION 19 // ---------------------------------------------------------------------------- --- 67,71 ---- //----------------------------------------------------------------------------- ! #define WXLUA_BINDING_VERSION 20 // ---------------------------------------------------------------------------- Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** wxlbind.h 19 Dec 2007 06:16:35 -0000 1.73 --- wxlbind.h 20 Dec 2007 02:26:57 -0000 1.74 *************** *** 23,42 **** // ---------------------------------------------------------------------------- ! // Generic delete function for binding objects ! WXDLLIMPEXP_WXLUA int LUACALL wxLua_wxluabind_delete(lua_State *L); // memory deallocation function for created wxLuaBindClass defined objects, Lua's __gc metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxluabind__gc_wxLuaBindClass(lua_State *L); // Lua 'set table' function for created wxLuaBindClass defined objects, Lua's __newindex metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxluabind__newindex_wxLuaBindClass(lua_State *L); // Lua 'get table' function for created wxLuaBindClass defined objects, Lua's __index metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxluabind__index_wxLuaBindClass(lua_State *L); // Lua 'tostring' function for created wxLuaBindClass defined objects, Lua's __tostring metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxluabind__tostring_wxLuaBindClass(lua_State *L); ! ! // If there is a special userdata upvalue, remove 1 value if !only_check ! // (hack to remove the table Lua pushes onto the stack when calling the ! // __call metatable function for class constructors) ! WXDLLIMPEXP_WXLUA int wxluabind_removetableforcall(lua_State* L, bool only_check = false); // ---------------------------------------------------------------------------- --- 23,37 ---- // ---------------------------------------------------------------------------- ! // Generic delete function for userdata binding objects ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_userdata_delete(lua_State *L); // memory deallocation function for created wxLuaBindClass defined objects, Lua's __gc metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__gc(lua_State *L); // Lua 'set table' function for created wxLuaBindClass defined objects, Lua's __newindex metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__newindex(lua_State *L); // Lua 'get table' function for created wxLuaBindClass defined objects, Lua's __index metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__index(lua_State *L); // Lua 'tostring' function for created wxLuaBindClass defined objects, Lua's __tostring metatable index ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__tostring(lua_State *L); // ---------------------------------------------------------------------------- *************** *** 51,70 **** // represents function prototype argument types. // wxlua arg tags for common Lua types - #define WXLUAARG_None 0 // LUA_TNONE - #define WXLUAARG_Unknown -1 // unset and invalid - #define WXLUAARG_Nil -2 // LUA_TNIL - #define WXLUAARG_Boolean -3 // LUA_TBOOLEAN - #define WXLUAARG_LightUserData -4 // LUA_TLIGHTUSERDATA - #define WXLUAARG_Number -5 // LUA_TNUMBER - #define WXLUAARG_String -6 // LUA_TSTRING - #define WXLUAARG_Table -7 // LUA_TTABLE - #define WXLUAARG_Function -8 // LUA_TFUNCTION - #define WXLUAARG_UserData -9 // LUA_TUSERDATA - #define WXLUAARG_Thread -10 // LUA_TTHREAD - #define WXLUAARG_Integer -11 // LUA_TNUMBER bit wants only an integer - #define WXLUAARG_CFunction -12 // LUA_TFUNCTION & lua_iscfunction, not a LUA_TXXX ! #define WXLUAARG__MIN -13 // Min of the WXLUAARG_XXX values // Variables used in the wxLuaArgTag member of the wxLuaBindCFunc for --- 46,72 ---- // represents function prototype argument types. + // Note: WXLUA_TXXX = -1*LUA_TXXX - 2 + // wxlua arg tags for common Lua types ! #define WXLUA_TUNKNOWN 0 // unset and invalid, not a LUA_TXXX ! #define WXLUA_TNONE -1 // LUA_TNONE -1 ! #define WXLUA_TNIL -2 // LUA_TNIL 0 ! #define WXLUA_TBOOLEAN -3 // LUA_TBOOLEAN 1 ! #define WXLUA_TLIGHTUSERDATA -4 // LUA_TLIGHTUSERDATA 2 ! #define WXLUA_TNUMBER -5 // LUA_TNUMBER 3 ! #define WXLUA_TSTRING -6 // LUA_TSTRING 4 ! #define WXLUA_TTABLE -7 // LUA_TTABLE 5 ! #define WXLUA_TFUNCTION -8 // LUA_TFUNCTION 6 ! #define WXLUA_TUSERDATA -9 // LUA_TUSERDATA 7 ! #define WXLUA_TTHREAD -10 // LUA_TTHREAD 8 ! #define WXLUA_TINTEGER -11 // LUA_TNUMBER but integer only, not a LUA_TXXX ! #define WXLUA_TCFUNCTION -12 // LUA_TFUNCTION & lua_iscfunction(), not a LUA_TXXX ! ! #define WXLUA_T_MAX 0 // Max of the WXLUA_TXXX values ! #define WXLUA_T_MIN -12 // Min of the WXLUA_TXXX values ! ! // Blindly convert the lua_type to the wxlua_type, see wxlua_getwxluatype() for better function ! #define LUAT_TO_WXLUAT(luatype) (-1*(luatype) - 2) // Variables used in the wxLuaArgTag member of the wxLuaBindCFunc for *************** *** 85,89 **** // copies of wxlua arg tags for binding types that are used very often - extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_wxLuaFunction; // The Lua tag for wxLuaFunctions extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_NULL; // The Lua tag for NULL pointer extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_wxEvent; // The Lua tag for wxEvents --- 87,90 ---- *************** *** 110,126 **** WXLUAMETHOD_STATIC = 0x1000, // Class member function is static - WXLUAMETHOD_OVERLOAD = 0x2000, // This is an overload function that will call others - // and the min/maxargs for it are not valid, - // but are the min and max of all functions ! WXLUAMETHOD_DELETE = 0x4000, // This is the delete function that wxLua has generated // to delete this class and is not part of the // original class. ! WXLUAMETHOD_OVERLOAD_BASE = 0x8000, // Class method has been checked to see if it is ! // overloaded from the base class by the function ! // wxLuaState::RegisterBindings() ! // Check wxLuaBindMethod::basemethod and if !NULL ! // this method is an overload from the base class }; --- 111,124 ---- WXLUAMETHOD_STATIC = 0x1000, // Class member function is static ! WXLUAMETHOD_DELETE = 0x2000, // This is the delete function that wxLua has generated // to delete this class and is not part of the // original class. ! WXLUAMETHOD_OVERLOAD_BASE = 0x10000, // Class method has been checked to see if it is ! // overloaded from the base class by the function ! // wxLuaState::RegisterBindings() ! // Check wxLuaBindMethod::basemethod and if !NULL ! // this method is an overload from the base class }; *************** *** 220,257 **** // ---------------------------------------------------------------------------- - // wxLuaFunction - a proxy class to store a reference to a Lua function. - // ---------------------------------------------------------------------------- - - class WXDLLIMPEXP_WXLUA wxLuaFunction - { - public: - wxLuaFunction(wxLuaBindMethod *wxlMethod, void *pObject) - : m_wxlMethod(wxlMethod), m_pObject(pObject) {} - - ~wxLuaFunction() {} - - int CallMethod(lua_State *L); // call wxLuaBindMethod->func[0](L) - void *GetObject() const { return m_pObject; } - - wxLuaBindMethod *m_wxlMethod; // Method to call for Lua's __call - void *m_pObject; // the actual object wrapped by a Lua userdata - }; - - // Garbage collect and free memory associated with the wxLuaFunction class - // Lua's __gc metatable function. - int LUACALL wxlua__gc_wxLuaFunction(lua_State *L); - // call a wxLuaFunction, Lua's __call metatable function. - int LUACALL wxlua__call_wxLuaFunction(lua_State *L); - - // ---------------------------------------------------------------------------- // Central function to call for overloaded functions // ---------------------------------------------------------------------------- // Redirect Lua function call to 1 method from a list of overloaded functions ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_CallOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod); ! // Get a human readable string of the Lua args (items on the stack) for a function call WXDLLIMPEXP_WXLUA wxString wxlua_getLuaArgsMsg(lua_State* L, int start_stack_idx, int end_stack_idx); - // Get a human readable wxArrayString of the wxLua args for the functions in the method WXDLLIMPEXP_WXLUA wxArrayString wxlua_getBindMethodArgsMsg(lua_State* L, struct wxLuaBindMethod* method); --- 218,232 ---- // ---------------------------------------------------------------------------- // Central function to call for overloaded functions // ---------------------------------------------------------------------------- // Redirect Lua function call to 1 method from a list of overloaded functions ! // if the 1st upvalue is a wxLuaBindMethod. ! int LUACALL wxlua_callOverloadedFunction(lua_State* L); ! // Redirect Lua function call to 1 method from a list of overloaded functions declared ! // in the wxLuaBindMethod. ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_callOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod); // Get a human readable string of the Lua args (items on the stack) for a function call WXDLLIMPEXP_WXLUA wxString wxlua_getLuaArgsMsg(lua_State* L, int start_stack_idx, int end_stack_idx); // Get a human readable wxArrayString of the wxLua args for the functions in the method WXDLLIMPEXP_WXLUA wxArrayString wxlua_getBindMethodArgsMsg(lua_State* L, struct wxLuaBindMethod* method); *************** *** 568,571 **** --- 543,550 ---- static const wxLuaBindEvent* GetBindEvent(wxEventType eventType_, const wxLuaBindingList* bindingList); + // Get the wxLuaBinding that has this wxLuaBindMethod in it's wxLuaBinding::GetFunctionArray(). + // returns NULL on failure. + static wxLuaBinding* GetFunctionBinding(const wxLuaBindMethod* method, const wxLuaBindingList* bindingList); + // ----------------------------------------------------------------------- // These functions search through the input struct Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** wxlstate.h 19 Dec 2007 06:16:35 -0000 1.110 --- wxlstate.h 20 Dec 2007 02:26:57 -0000 1.111 *************** *** 240,249 **** // Leaves the new table on the top of the stack. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_newtag(lua_State* L); ! // Get the numeric tag of the object at the stack index using the metatable's wxlua_metatable_tag_key key. ! // Returns WXLUA_NOTAG if the metatable of the object doesn't have a wxlua_metatable_tag_key // key or it isn't a number. The tag is presumedly the index into the wxlua_lreg_tags_key // LUA_REGISTRYINDEX table and denotes what type of C++ object this is. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_gettag(lua_State* L, int stack_idx); ! // Set the metatable of the object at top of stack to the table stored in the // wxlua_lreg_tags_key LUA_REGISTRYINDEX table using wxluaR_getref(L, wxl_tag). WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_settag(lua_State* L, int wxl_tag); --- 240,249 ---- // Leaves the new table on the top of the stack. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_newtag(lua_State* L); ! // Get the numeric tag of the userdata at the stack index using the metatable's wxlua_metatable_tag_key key. ! // Returns WXLUA_NOTAG if the metatable of the userdata doesn't have a wxlua_metatable_tag_key // key or it isn't a number. The tag is presumedly the index into the wxlua_lreg_tags_key // LUA_REGISTRYINDEX table and denotes what type of C++ object this is. WXDLLIMPEXP_WXLUA int LUACALL wxluaT_gettag(lua_State* L, int stack_idx); ! // Set the metatable of the userdata at top of stack to the table stored in the // wxlua_lreg_tags_key LUA_REGISTRYINDEX table using wxluaR_getref(L, wxl_tag). WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_settag(lua_State* L, int wxl_tag); *************** *** 264,268 **** // Get the userdata object at the stack_idx that is of the class type tag or a ! // class derived from the tag. If the data type does not have the correct tag, // or if the parameter isn't a userdata then wxlua_error() is called and NULL is returned. WXDLLIMPEXP_WXLUA void* LUACALL wxluaT_getuserdatatype(lua_State* L, int stack_idx, int wxl_tag); --- 264,268 ---- // Get the userdata object at the stack_idx that is of the class type tag or a ! // class derived from the tag. If the userdata does not have the correct tag, // or if the parameter isn't a userdata then wxlua_error() is called and NULL is returned. WXDLLIMPEXP_WXLUA void* LUACALL wxluaT_getuserdatatype(lua_State* L, int stack_idx, int wxl_tag); *************** *** 272,276 **** // If track=true then push the obj_ptr as a lightuser data key into the // wxlua_lreg_weakobjects_key table of the Lua LUA_REGISTRYINDEX table so ! // that if we need to push it again we just push the full userdata value. WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_pushusertag(lua_State* L, const void* obj_ptr, int wxl_tag, bool track); // Push a data type onto the stack and set its tag by calling wxluaT_pushusertag() --- 272,276 ---- // If track=true then push the obj_ptr as a lightuser data key into the // wxlua_lreg_weakobjects_key table of the Lua LUA_REGISTRYINDEX table so ! // that if we need to push it again we just push the already created full userdata value. WXDLLIMPEXP_WXLUA bool LUACALL wxluaT_pushusertag(lua_State* L, const void* obj_ptr, int wxl_tag, bool track); // Push a data type onto the stack and set its tag by calling wxluaT_pushusertag() *************** *** 342,346 **** // to the wxlua_lreg_topwindows_key table of the LUA_REGISTRYINDEX table if // it has not already been added. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaW_addtrackedwindow(lua_State *L, wxObject* obj); // Remove the wxWindow from the wxlua_lreg_topwindows_key table of the // LUA_REGISTRYINDEX table. --- 342,346 ---- // to the wxlua_lreg_topwindows_key table of the LUA_REGISTRYINDEX table if // it has not already been added. ! WXDLLIMPEXP_WXLUA void LUACALL wxluaW_addtrackedwindow(lua_State *L, wxObject* wxobj); // Remove the wxWindow from the wxlua_lreg_topwindows_key table of the // LUA_REGISTRYINDEX table. *************** *** 366,383 **** WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* base_wxlClass); // Verify if the luatype = lua_type(L, stack_idx) is valid for the ! // wxluaarg_tag which is one of the predefined WXLUAARG_XXX or s_wxluaarg_XXX types. // Returns 1 if it matches, 0 if it doesn't, -1 if the wxluaarg_tag is not known. // Note that this function does not do a direct mapping between wxlua_getwxluatype() // and wxlua_getluatype() since it allows a small amount of coersion between types. // If the input lua_State is not NULL it will account for the automatic conversion of ! // (wxString, wxArrayString, wxArrayInt) to and from Lua types to wxluatypes, ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_iswxluatype(int luatype, int wxluaarg_tag, lua_State* L = NULL); ! // Get a human readable name for the predefined WXLUAARG_XXX or s_wxluaarg_XXX tags. ! // returns empty string if the tag was not one of the predefined types. ! WXDLLIMPEXP_WXLUA wxString wxlua_getwxluatypename(int wxluaarg_tag); // Get the wxluaarg_tag for the lua_type() = LUA_TXXX. // returns -1 if the tag was not one of the predefined types. WXDLLIMPEXP_WXLUA int wxlua_getwxluatype(int luatype); ! // Get the lua_type() = LUA_TXXX for the predefined WXLUAARG_XXX or s_wxluaarg_XXX tags. // returns -1 (LUA_TNONE) if the tag was not one of the predefined types. WXDLLIMPEXP_WXLUA int wxlua_getluatype(int wxluatype); --- 366,384 ---- WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* base_wxlClass); // Verify if the luatype = lua_type(L, stack_idx) is valid for the ! // wxluaarg_tag which is one of the predefined WXLUA_TXXX or s_wxluaarg_XXX types. // Returns 1 if it matches, 0 if it doesn't, -1 if the wxluaarg_tag is not known. // Note that this function does not do a direct mapping between wxlua_getwxluatype() // and wxlua_getluatype() since it allows a small amount of coersion between types. // If the input lua_State is not NULL it will account for the automatic conversion of ! // (wxString, wxArrayString, wxArrayInt) from the Lua type to wxlua tags, ! WXDLLIMPEXP_WXLUA int LUACALL wxlua_iswxluatype(int luatype, int wxlarg_tag, lua_State* L = NULL); ! // Get a human readable name for the predefined WXLUA_TXXX or s_wxluaarg_XXX tags. ! // returns empty string if the tag was not one of the predefined arg types. ! // If the lua_State is not NULL then return the wxLua tag (C++ class) name. ! WXDLLIMPEXP_WXLUA wxString wxlua_getwxluatypename(int wxlarg_tag, lua_State* L = NULL); // Get the wxluaarg_tag for the lua_type() = LUA_TXXX. // returns -1 if the tag was not one of the predefined types. WXDLLIMPEXP_WXLUA int wxlua_getwxluatype(int luatype); ! // Get the lua_type() = LUA_TXXX for the predefined WXLUA_TXXX or s_wxluaarg_XXX tags. // returns -1 (LUA_TNONE) if the tag was not one of the predefined types. WXDLLIMPEXP_WXLUA int wxlua_getluatype(int wxluatype); *************** *** 396,403 **** // always allow coersion between types since oftentimes there's an error. WXDLLIMPEXP_WXLUA bool wxlua_iswxstringtype(lua_State* L, int stack_idx); ! #define wxlua_isstringtype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_String) == 1) ! #define wxlua_isbooleantype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_Boolean) == 1) ! #define wxlua_isintegertype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_Integer) == 1) ! #define wxlua_isnumbertype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_Number) == 1) // After verifying using wxlua_isXXXtype return the value, else call --- 397,404 ---- // always allow coersion between types since oftentimes there's an error. WXDLLIMPEXP_WXLUA bool wxlua_iswxstringtype(lua_State* L, int stack_idx); ! #define wxlua_isstringtype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUA_TSTRING) == 1) ! #define wxlua_isbooleantype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUA_TBOOLEAN) == 1) ! #define wxlua_isintegertype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUA_TINTEGER) == 1) ! #define wxlua_isnumbertype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUA_TNUMBER) == 1) // After verifying using wxlua_isXXXtype return the value, else call *************** *** 910,914 **** // Verify if the luatype = lua_type(L, stack_idx) is valid for the ! // wxluaarg_tag which is one of the predefined WXLUAARG_XXX or s_wxluaarg_XXX types. // Returns 1 if it matches, 0 if it doesn't, -1 if the wxluaarg_tag is not known. // Note that this function does not do a direct mapping between wxlua_getwxluatype() --- 911,915 ---- // Verify if the luatype = lua_type(L, stack_idx) is valid for the ! // wxluaarg_tag which is one of the predefined WXLUA_TXXX or s_wxluaarg_XXX types. // Returns 1 if it matches, 0 if it doesn't, -1 if the wxluaarg_tag is not known. // Note that this function does not do a direct mapping between wxlua_getwxluatype() Index: wxlua_bind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlua_bind.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** wxlua_bind.h 10 Dec 2007 05:39:10 -0000 1.8 --- wxlua_bind.h 20 Dec 2007 02:26:57 -0000 1.9 *************** *** 17,23 **** // the current version of the bindings. // See 'bindings/genwxbind.lua' and 'modules/wxlua/include/wxldefs.h' ! #if WXLUA_BINDING_VERSION > 19 # error "The WXLUA_BINDING_VERSION in the bindings is too old, regenerate bindings." ! #endif //WXLUA_BINDING_VERSION > 19 // --------------------------------------------------------------------------- --- 17,23 ---- // the current version of the bindings. // See 'bindings/genwxbind.lua' and 'modules/wxlua/include/wxldefs.h' ! #if WXLUA_BINDING_VERSION > 20 # error "The WXLUA_BINDING_VERSION in the bindings is too old, regenerate bindings." ! #endif //WXLUA_BINDING_VERSION > 20 // --------------------------------------------------------------------------- |