From: John L. <jr...@us...> - 2007-06-12 00:08:48
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv4216/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlcallb.h wxldefs.h wxlstate.h Log Message: Change wxLuaState::AddTrackedWindow to take a wxObject and figure out inside if it's a window Change the nomenclature "enum" to "integer" as the integer data type Change "base_"XXX to "_"XXX for base class function calls Add a test function to wxLuaPrintout to really check if virtual functions work More fixes to samples for binding changes Index: wxlcallb.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlcallb.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** wxlcallb.h 14 Dec 2006 01:01:26 -0000 1.15 --- wxlcallb.h 12 Jun 2007 00:08:42 -0000 1.16 *************** *** 33,39 **** // winID and lastID follow the same notation as wxEvtHandler::Connect // if only one event Id is needed set lastId = wxID_ANY ! wxLuaCallback( const wxLuaState& state, int lua_func_stack_idx, wxWindowID winId, wxWindowID lastId, ! wxEventType eventType, wxEvtHandler *pHandler ); virtual ~wxLuaCallback(); --- 33,39 ---- // winID and lastID follow the same notation as wxEvtHandler::Connect // if only one event Id is needed set lastId = wxID_ANY ! wxLuaCallback( const wxLuaState& wxlState, int lua_func_stack_idx, wxWindowID winId, wxWindowID lastId, ! wxEventType eventType, wxEvtHandler *evtHandler ); virtual ~wxLuaCallback(); *************** *** 41,66 **** void ClearwxLuaState() { m_wxlState.UnRef(); } ! wxLuaState GetwxLuaState() const { return m_wxlState; } ! wxWindowID GetId() const { return m_id; } ! wxWindowID GetLastId() const { return m_lastId; } ! wxEventType GetEventType() const { return m_eventType; } ! wxEvtHandler *GetEvtHandler() const { return m_pHandler; } // Central event handler that calls CallFunction() for the actual ! // wxLuaCallback callback user data void EventHandler(wxEvent& event); // Handle the event by calling the lua function to handle the event. // The lua function will receive a single parameter, the type of event. ! virtual void CallFunction(wxEvent *pEvent); protected: ! int m_routine; // reference to the lua routine to call ! ! // store the wxLuaState since we're added to a list of it's callbacks. ! wxLuaState m_wxlState; ! wxEvtHandler* m_pHandler; ! wxWindowID m_id; ! wxWindowID m_lastId; ! wxEventType m_eventType; private: --- 41,68 ---- void ClearwxLuaState() { m_wxlState.UnRef(); } ! wxLuaState GetwxLuaState() const { return m_wxlState; } ! wxWindowID GetId() const { return m_id; } ! wxWindowID GetLastId() const { return m_lastId; } ! wxEventType GetEventType() const { return m_wxlBindEvent ? *m_wxlBindEvent->eventType : wxEVT_NULL; } ! wxEvtHandler* GetEvtHandler() const { return m_evtHandler; } ! ! const wxLuaBindEvent* GetwxLuaBindEvent() const { return m_wxlBindEvent; } // Central event handler that calls CallFunction() for the actual ! // wxLuaCallback callback user data. This function is treated like a ! // static function that all handlers of this class will call. void EventHandler(wxEvent& event); + // Handle the event by calling the lua function to handle the event. // The lua function will receive a single parameter, the type of event. ! virtual void CallFunction(wxEvent *event); protected: ! int m_routine; // ref to the lua routine to call in the wxLuaReferences registry table ! wxLuaState m_wxlState; // store it since we're added to a list of it's callbacks. ! wxEvtHandler* m_evtHandler; ! wxWindowID m_id; ! wxWindowID m_lastId; ! const wxLuaBindEvent* m_wxlBindEvent; // data for this wxEventType private: *************** *** 80,84 **** public: wxLuaWinDestroyCallback(const wxLuaState& state, ! wxWindowID id, wxEvtHandler *pHandler, int iTag); --- 82,86 ---- public: wxLuaWinDestroyCallback(const wxLuaState& state, ! wxWindowID id, wxEvtHandler *evtHandler, int iTag); *************** *** 87,104 **** void ClearwxLuaState() { m_wxlState.UnRef(); } ! wxLuaState GetwxLuaState() const { return m_wxlState; } ! int GetId() const { return m_id; } ! wxEvtHandler* GetEvtHandler() const { return m_pHandler; } // Central event handler that calls OnDestroy() for the actual // wxLuaWinDestroyCallback callback user data void EventHandler(wxWindowDestroyEvent& event); // Handle the event by clearing the metatable for the window virtual void OnDestroy(wxWindowDestroyEvent& event); ! protected: ! // store the wxLuaState since we're added to a list of it's callbacks. ! wxLuaState m_wxlState; ! wxEvtHandler* m_pHandler; int m_id; --- 89,106 ---- void ClearwxLuaState() { m_wxlState.UnRef(); } ! wxLuaState GetwxLuaState() const { return m_wxlState; } ! int GetId() const { return m_id; } ! wxEvtHandler* GetEvtHandler() const { return m_evtHandler; } // Central event handler that calls OnDestroy() for the actual // wxLuaWinDestroyCallback callback user data void EventHandler(wxWindowDestroyEvent& event); + // Handle the event by clearing the metatable for the window virtual void OnDestroy(wxWindowDestroyEvent& event); ! protected: ! wxLuaState m_wxlState; // store it since we're added to a list of it's callbacks. ! wxEvtHandler* m_evtHandler; int m_id; Index: wxldefs.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxldefs.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** wxldefs.h 8 Jun 2007 03:40:51 -0000 1.21 --- wxldefs.h 12 Jun 2007 00:08:42 -0000 1.22 *************** *** 99,105 **** #if wxUSE_UNICODE ! #define wxLUA_UNUSED_NOTUNICODE(x) x #else /* !Unicode */ ! #define wxLUA_UNUSED_NOTUNICODE(x) #endif // wxUSE_UNICODE --- 99,105 ---- #if wxUSE_UNICODE ! #define wxLUA_UNICODE_ONLY(x) x #else /* !Unicode */ ! #define wxLUA_UNICODE_ONLY(x) #endif // wxUSE_UNICODE Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** wxlbind.h 11 Jun 2007 03:58:10 -0000 1.47 --- wxlbind.h 12 Jun 2007 00:08:42 -0000 1.48 *************** *** 20,24 **** // ---------------------------------------------------------------------------- ! // C functions for lua installed by the wxLuaBinding // ---------------------------------------------------------------------------- --- 20,24 ---- // ---------------------------------------------------------------------------- ! // C functions for the metatable for wxLua userdata installed by the wxLuaBinding // ---------------------------------------------------------------------------- *************** *** 38,41 **** --- 38,76 ---- // ---------------------------------------------------------------------------- + // Binding tags are generated as positive tag id automatically when bound + // so we set the inbuilt lua arg tags to negative values + // + // note that -1 is use as initialiser for class tags + // and 0 is used as an end marker for the wxLuaArgTag array that + // represents function prototype argument types. + + // wxlua arg tags for common lua types + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_None; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Nil; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Boolean; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LightUserData; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Number; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_String; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaTable; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaFunction; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_UserData; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaThread; + extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Integer; + + #define WXLUAARG_None 0 + #define WXLUAARG_Nil -2 + #define WXLUAARG_Boolean -3 + #define WXLUAARG_LightUserData -4 + #define WXLUAARG_Number -5 + #define WXLUAARG_String -6 + #define WXLUAARG_LuaTable -7 + #define WXLUAARG_LuaFunction -8 + #define WXLUAARG_UserData -9 + #define WXLUAARG_LuaThread -10 + #define WXLUAARG_Integer -11 + + typedef int* wxLuaArgTag; // address of class tag (a pointer to it) + extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgTag) s_wxluaargArray_None[1]; // = {0} + enum wxLuaMethod_Type // The type of a Lua method { *************** *** 58,67 **** }; - typedef int* wxLuaArgTag; // address of class tag (a pointer to it) - extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgTag) s_wxluaargArray_None[1]; // = {0} - struct WXDLLIMPEXP_WXLUA wxLuaBindCFunc // defines a single C func for a LUA method { ! lua_CFunction func; // function that implements the method or property int type; // wxLuaMethod_Type flags for this function int minargs; // min number of required args --- 93,99 ---- }; struct WXDLLIMPEXP_WXLUA wxLuaBindCFunc // defines a single C func for a LUA method { ! lua_CFunction func; // C function that implements the method or property int type; // wxLuaMethod_Type flags for this function int minargs; // min number of required args *************** *** 78,113 **** int type; // wxLuaMethod_Type flags for this method // note each func has own type, this is ored values of them ! wxLuaBindCFunc *funcs; // array of functions for this method ! int funcs_n; // number of functions (overloaded > 1) for this method wxLuaBindMethod *basemethod; // overloaded methods from base class, else NULL // see comments for WXLUAMETHOD_OVERLOAD_BASE }; - // wxlua arg tags for common lua types - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_None; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Nil; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Boolean; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LightUserData; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Number; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_String; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaTable; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaFunction; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_UserData; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_LuaThread; - extern WXDLLIMPEXP_DATA_WXLUA(int) s_wxluaarg_Enum; - - #define WXLUAARG_None 0 - #define WXLUAARG_Nil -2 - #define WXLUAARG_Boolean -3 - #define WXLUAARG_LightUserData -4 - #define WXLUAARG_Number -5 - #define WXLUAARG_String -6 - #define WXLUAARG_LuaTable -7 - #define WXLUAARG_LuaFunction -8 - #define WXLUAARG_UserData -9 - #define WXLUAARG_LuaThread -10 - #define WXLUAARG_Enum -11 - - struct WXDLLIMPEXP_WXLUA wxLuaBindDefine // defines a numeric define for wxLua { --- 110,119 ---- int type; // wxLuaMethod_Type flags for this method // note each func has own type, this is ored values of them ! wxLuaBindCFunc *funcs; // array of C functions for this method ! int funcs_n; // number of C functions (overloaded > 1) for this method wxLuaBindMethod *basemethod; // overloaded methods from base class, else NULL // see comments for WXLUAMETHOD_OVERLOAD_BASE }; struct WXDLLIMPEXP_WXLUA wxLuaBindDefine // defines a numeric define for wxLua { *************** *** 126,132 **** struct WXDLLIMPEXP_WXLUA wxLuaBindEvent // defines a wxWidgets Event for wxLua { ! const char *name; // name of the event, e.g. "wxEVT_COMMAND_MENU_SELECTED" ! const int *eventType; // wxWidgets event type, e.g. &wxEVT_COMMAND_MENU_SELECTED ! int *class_tag; // lua class tag, e.g. &s_wxluatag_wxCommandEvent }; --- 132,138 ---- struct WXDLLIMPEXP_WXLUA wxLuaBindEvent // defines a wxWidgets Event for wxLua { ! const char *name; // name of the event, e.g. "wxEVT_COMMAND_MENU_SELECTED" ! const wxEventType *eventType; // wxWidgets event type, e.g. &wxEVT_COMMAND_MENU_SELECTED ! int *class_tag; // lua class tag, e.g. &s_wxluatag_wxCommandEvent }; *************** *** 153,157 **** // See wxLuaBinding::SetBaseClass ! wxLuaBindDefine* enums; // Class member enums int enums_n; // number of enums }; --- 159,163 ---- // See wxLuaBinding::SetBaseClass ! wxLuaBindDefine* enums; // Class member enums (if any) int enums_n; // number of enums }; *************** *** 202,206 **** { public: ! // Wrap the item at the lua state's stack index and create a reference to it. wxLuaObject(const wxLuaState& wxlState, int stack_idx = 1); --- 208,213 ---- { public: ! // Wrap the item at the lua_State's stack index and create a reference to it. ! // in the wxLuaReferences registy table wxLuaObject(const wxLuaState& wxlState, int stack_idx = 1); *************** *** 218,222 **** // Call GetObject() so that it's on the stack then try to get the value of // the object as the specified type and set the member variable equal to it ! // and return a pointer to member variable. bool *GetBoolPtr(); int *GetIntPtr(); --- 225,230 ---- // Call GetObject() so that it's on the stack then try to get the value of // the object as the specified type and set the member variable equal to it ! // and return a pointer to member variable to a function that wants ! // a pointer to read/write from/to. bool *GetBoolPtr(); int *GetIntPtr(); *************** *** 235,239 **** private: wxLuaState* m_wxlState; // a pointer due to include recursion. ! int m_iReference; bool m_bool; int m_int; --- 243,247 ---- private: wxLuaState* m_wxlState; // a pointer due to include recursion. ! int m_reference; bool m_bool; int m_int; *************** *** 388,400 **** // ----------------------------------------------------------------------- ! // Lookup a lua method or get property called cpIndex in the wxLuaBindClass array pClass ! // Ensure that the lookup is of the required type. If the lua method ! // can not be found on the current class recurse through base classes // Return a pointer to the wxLuaBindMethod that corresponds to the method name, // else return NULL; static wxLuaBindMethod* GetClassMethod(const wxLuaBindClass *wxlClass, const char *methodName, bool search_baseclasses = true); ! // Lookup a lua property function named cpIndex in the wxLuaBindClass pClass ! // Ensure that the lookup is of the required type. If the lua property ! // can not be found on the current class recurse through base classes // Return a pointer to the wxLuaBindMethod that corresponds to the property name, // else return NULL; --- 396,408 ---- // ----------------------------------------------------------------------- ! // Lookup a lua method or get property called methodName in the wxLuaBindClass array wxlClass. ! // Ensure that the lookup is of WXLUAMETHOD_METHOD|WXLUAMETHOD_GETPROP type. ! // If the lua method cannot be found on the current class recurse through base classes // Return a pointer to the wxLuaBindMethod that corresponds to the method name, // else return NULL; static wxLuaBindMethod* GetClassMethod(const wxLuaBindClass *wxlClass, const char *methodName, bool search_baseclasses = true); ! // Lookup a lua property function named propName in the wxLuaBindClass wxlClass ! // Ensure that the lookup is of WXLUAMETHOD_GETPROP|WXLUAMETHOD_SETPROP type. ! // If the lua property cannot be found on the current class recurse through base classes // Return a pointer to the wxLuaBindMethod that corresponds to the property name, // else return NULL; Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** wxlstate.h 11 Jun 2007 03:58:10 -0000 1.75 --- wxlstate.h 12 Jun 2007 00:08:42 -0000 1.76 *************** *** 96,106 **** #define wxlua_pushstring_wxLuaReferences(L) lua_pushlstring(L, "wxLuaReferences", 15) // Push the "wxLuaClasses" string onto the stack. This is the name of an ! // index in the LUA_REGISTRYINDEX table that is // t[wxLuaBindClass.name] = wxLuaBindClass, where the wxLuaBindClass is a lightuserdata. #define wxlua_pushstring_wxLuaClasses(L) lua_pushlstring(L, "wxLuaClasses", 12) ! // Push the "wxLuaDerivedFunctions" string onto the stack. This is the name of an // index in the LUA_REGISTRYINDEX table that is a table // t[lightuserdata object] = {["derived func/value name"] = wxLuaObject(lua function/value), ...} ! #define wxlua_pushstring_wxLuaDerivedFunctions(L) lua_pushlstring(L, "wxLuaDerivedFunctions", 21) // Push the "wxLuaStateRefData" string onto the stack. This is the name of an // index of the LUA_REGISTRYINDEX table that is a lightuserdata of the --- 96,106 ---- #define wxlua_pushstring_wxLuaReferences(L) lua_pushlstring(L, "wxLuaReferences", 15) // Push the "wxLuaClasses" string onto the stack. This is the name of an ! // index in the LUA_REGISTRYINDEX table that is a table // t[wxLuaBindClass.name] = wxLuaBindClass, where the wxLuaBindClass is a lightuserdata. #define wxlua_pushstring_wxLuaClasses(L) lua_pushlstring(L, "wxLuaClasses", 12) ! // Push the "wxLuaDerivedMethods" string onto the stack. This is the name of an // index in the LUA_REGISTRYINDEX table that is a table // t[lightuserdata object] = {["derived func/value name"] = wxLuaObject(lua function/value), ...} ! #define wxlua_pushstring_wxLuaDerivedMethods(L) lua_pushlstring(L, "wxLuaDerivedMethods", 19) // Push the "wxLuaStateRefData" string onto the stack. This is the name of an // index of the LUA_REGISTRYINDEX table that is a lightuserdata of the *************** *** 132,135 **** --- 132,136 ---- // Push the errorMsg on the stack and call lua_error WXDLLIMPEXP_WXLUA void LUACALL wxlua_terror(lua_State* L, const char* errorMsg); + wxLUA_UNICODE_ONLY(WXDLLIMPEXP_WXLUA void LUACALL wxlua_terror(lua_State* L, const wxString& errorMsg) { wxlua_terror(L, wx2lua(errorMsg)); }) // Push the object u onto the top of the stack wrapped in a newuserdata // with it's metatable set to the table from tget(tag). Returns true if the *************** *** 164,170 **** // ---------------------------------------------------------------------------- ! // Get the wxLuaBindClass* for this class_tag or NULL if the tag is invalid WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, int class_tag); ! // Get the wxLuaBindClass* for this class_name or NULL if the name is invalid WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, const char* class_name); // Is a class with the class_tag equal to or derived from a class with the base_class_tag. --- 165,174 ---- // ---------------------------------------------------------------------------- ! // Get the wxLuaBindClass* for this class_tag or NULL if the tag is invalid. ! // Gets the wxLuaBindClass from the metatable stored in the wxLuaReferences registry table ! // for the classes that have been installed into lua. WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, int class_tag); ! // Get the wxLuaBindClass* for this class_name or NULL if the name is invalid. ! // Gets the wxLuaBindClass from the "wxLuaClasses" table in the lua registry. WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, const char* class_name); // Is a class with the class_tag equal to or derived from a class with the base_class_tag. *************** *** 172,175 **** --- 176,180 ---- // returns -1 if the class_tag is not derived from the base class WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(lua_State* L, int class_tag, int base_class_tag); + // Same as above, but works directly with the wxLuaBindClasses. WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* wxlBaseClass); // Verify if the luatype = lua_type(L, stack_idx) is valid for the *************** *** 179,210 **** // and wxlua_getluatype() since it allows a small amount of coersion between types. // It also doesn't account for the automatic conversion of certain lua types ! // to wxluatypes, see wxLuaState::IswxLuaType which is more complete. WXDLLIMPEXP_WXLUA int LUACALL wxlua_iswxluatype(int luatype, int wxluaarg_tag); // 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(). // returns -1 if the tag was not one of the predefined types. WXDLLIMPEXP_WXLUA int wxlua_getwxluatype(int luatype); ! // Get the lua_type() 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); // Helper functions to get numbers, booleans and strings safer. // These validate that the object at the stack index specified is a string, bool, ! // enum, or double number object or that the object can be converted to it. // Note: wxLua has a stricter sense of type than lua and we don't want to // always allow coersion between types since oftentimes there's an error. ! #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_isenumerationtype(L, stack_idx) (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_Enum) == 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 // wxlua_terror with a message that's appropriate for stack_idx to be a // parameter to a function call. (These are used in the bindings) WXDLLIMPEXP_WXLUA const char* LUACALL wxlua_getstringtype(lua_State* L, int stack_idx); WXDLLIMPEXP_WXLUA bool LUACALL wxlua_getbooleantype(lua_State* L, int stack_idx); ! WXDLLIMPEXP_WXLUA long LUACALL wxlua_getenumerationtype(lua_State* L, int stack_idx); WXDLLIMPEXP_WXLUA double LUACALL wxlua_getnumbertype(lua_State* L, int stack_idx); --- 184,225 ---- // and wxlua_getluatype() since it allows a small amount of coersion between types. // It also doesn't account for the automatic conversion of certain lua types ! // to wxluatypes, (wxString, wxArrayString, wxArrayInt) ! // see wxLuaState::IswxLuaType which is more complete. WXDLLIMPEXP_WXLUA int LUACALL wxlua_iswxluatype(int luatype, int wxluaarg_tag); // 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); + // Is this data a userdata object that wxLua has pushed into lua? + // This should be the same as + // (lua_isuserdata(L, stack_idx) && !lua_islightuserdata(L, stack_idx)) + #define wxlua_iswxuserdata(L, stack_idx) (lua_type((L), (stack_idx)) == LUA_TUSERDATA) + // Helper functions to get numbers, booleans and strings safer. // These validate that the object at the stack index specified is a string, bool, ! // int, or double number object or that the object can be converted to it. // Note: wxLua has a stricter sense of type than lua and we don't want to // always allow coersion between types since oftentimes there's an error. ! // Note: The wxLuaState::IsStringType function takes both a lua string and a wxString ! // userdata as valid strings. ! #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 // wxlua_terror with a message that's appropriate for stack_idx to be a // parameter to a function call. (These are used in the bindings) + // Note: The function wxLuaState::GetwxStringType does automatic conversion + // of both a lua string and a userdata wxString to a wxString. WXDLLIMPEXP_WXLUA const char* LUACALL wxlua_getstringtype(lua_State* L, int stack_idx); WXDLLIMPEXP_WXLUA bool LUACALL wxlua_getbooleantype(lua_State* L, int stack_idx); ! WXDLLIMPEXP_WXLUA long LUACALL wxlua_getintegertype(lua_State* L, int stack_idx); WXDLLIMPEXP_WXLUA double LUACALL wxlua_getnumbertype(lua_State* L, int stack_idx); *************** *** 216,221 **** // Convert the table at stack index to a "new" array of const char* strings. ! // Return a pointer to the array of strings (you need to delete them) // returns the number of character strings in the array in count. WXDLLIMPEXP_WXLUA const char** LUACALL wxlua_getchararray(lua_State* L, int stack_idx, int& count); --- 231,239 ---- // Convert the table at stack index to a "new" array of const char* strings. ! // Return a pointer to the array of strings. You need to delete the array, but not ! // the individual strings since lua should still have them during the life of the ! // returned array, if not you will need to copy them. // returns the number of character strings in the array in count. + // See usage in the wxBitmap constructor for XPMs. WXDLLIMPEXP_WXLUA const char** LUACALL wxlua_getchararray(lua_State* L, int stack_idx, int& count); *************** *** 253,257 **** wxEventType m_inEventType; // wxEventType set when in event, else wxEVT_NULL ! wxLongToLongHashMap m_trackedObjects; // tracked objects. wxList m_callbackList; // event objects for wxLuaCallback wxList m_winDestroyCallbackList; // wxLuaWinDestroyCallback installed --- 271,280 ---- wxEventType m_inEventType; // wxEventType set when in event, else wxEVT_NULL ! wxLongToLongHashMap m_trackedObjects; // tracked wxObjects that we will delete when the ! // wxLuaState is closed or lua gc them. ! // key is (long)object* and value is the wxObject ! // Note that non wxObject classes use ! // wxLUA_DECLARE_ENCAPSULATION so the key is the object pointer ! // and the value is the wxObject encapsulation. wxList m_callbackList; // event objects for wxLuaCallback wxList m_winDestroyCallbackList; // wxLuaWinDestroyCallback installed *************** *** 302,318 **** // ------------------------------------------------------------------------ ! lua_State* m_lua_State; // the lua_State that "is" lua ! bool m_lua_State_static; // lua_close the lua_State if !static bool m_lua_State_coroutine; // this is a coroutine, don't close it wxLuaStateData* m_wxlStateData; // the data shared for this state ! bool m_own_stateData; // not a coroutine when true // Get the wxLuaStateRefData from the corresponding lua_State ! // returns NULL if none found static wxLuaStateRefData* GetLuaStateRefData(lua_State* L); // A mapping between hashmap[lua_State* L] = *wxLuaStateRefData ! // Note: The coroutines are not hashed since we cannot know when they ! // are deleted. We create wxLuaStates for them on the fly. static wxHashMapLuaStateRefData s_wxHashMapLuaStateRefData; }; --- 325,341 ---- // ------------------------------------------------------------------------ ! lua_State* m_lua_State; // the lua_State that "is" lua ! bool m_lua_State_static; // lua_close() the lua_State if !static bool m_lua_State_coroutine; // this is a coroutine, don't close it wxLuaStateData* m_wxlStateData; // the data shared for this state ! bool m_own_stateData; // not a coroutine when true, so delete it when done // Get the wxLuaStateRefData from the corresponding lua_State ! // returns NULL if none found. static wxLuaStateRefData* GetLuaStateRefData(lua_State* L); // A mapping between hashmap[lua_State* L] = *wxLuaStateRefData ! // Note: The coroutine lua_States are not hashed since we cannot know when ! // they are deleted. We create wxLuaStates for them on the fly. static wxHashMapLuaStateRefData s_wxHashMapLuaStateRefData; }; *************** *** 399,403 **** // Set the event handler that the wxLuaEvents from this will be sent to, can be NULL ! // see wxEVT_LUA_XXX for a list of possible events that may be sent void SetEventHandler(wxEvtHandler *evtHandler); wxEvtHandler *GetEventHandler() const; --- 422,426 ---- // Set the event handler that the wxLuaEvents from this will be sent to, can be NULL ! // see wxEVT_LUA_XXX for a list of possible events that may be sent. void SetEventHandler(wxEvtHandler *evtHandler); wxEvtHandler *GetEventHandler() const; *************** *** 454,465 **** // Break a currently running lua program by setting the lua debug hook to // be called for anything and breaking as soon as possible by calling ! // terror with the message void DebugHookBreak(const wxString &message = wxT("Lua interpreter stopped")); ! // Clear a previously set DebugHookBreak, resetting the debug hook // to the previous values void ClearDebugHookBreak(); // has DebugHookBreak() been called and we're waiting for the next hook call bool GetDebugHookBreak() const; ! // Get the message that will be sent when from a DebugHookBreak call wxString GetDebugHookBreakMessage() const; --- 477,488 ---- // Break a currently running lua program by setting the lua debug hook to // be called for anything and breaking as soon as possible by calling ! // terror() with the message void DebugHookBreak(const wxString &message = wxT("Lua interpreter stopped")); ! // Clear a previously set DebugHookBreak(), resetting the debug hook // to the previous values void ClearDebugHookBreak(); // has DebugHookBreak() been called and we're waiting for the next hook call bool GetDebugHookBreak() const; ! // Get the message that will be sent when from a DebugHookBreak() call wxString GetDebugHookBreakMessage() const; *************** *** 491,495 **** // Registers a new C function for Lua, see usage in wxlstate.cpp void RegisterFunction(lua_CFunction func, const char* funcName); ! wxLUA_UNUSED_NOTUNICODE(void RegisterFunction(lua_CFunction func, const wxString &funcName) { RegisterFunction(func, wx2lua(funcName)); }) // Register all the bindings in the wxLuaStateData, this is done // automatically by default on creation. (internal use) --- 514,518 ---- // Registers a new C function for Lua, see usage in wxlstate.cpp void RegisterFunction(lua_CFunction func, const char* funcName); ! wxLUA_UNICODE_ONLY(void RegisterFunction(lua_CFunction func, const wxString &funcName) { RegisterFunction(func, wx2lua(funcName)); }) // Register all the bindings in the wxLuaStateData, this is done // automatically by default on creation. (internal use) *************** *** 497,501 **** // Get the installed wxLuaBinding with the given ! // wxLuaBinding::GetBindingName or NULL for no match. wxLuaBinding* GetLuaBinding(const wxString& bindingName) const; --- 520,524 ---- // Get the installed wxLuaBinding with the given ! // wxLuaBinding::GetBindingName() or NULL for no match. wxLuaBinding* GetLuaBinding(const wxString& bindingName) const; *************** *** 551,556 **** // Add a wxWindow to track and delete when we're closed, only track ! // the parent window, not it's children. ! void AddTrackedWindow(wxWindow *win); // Don't track this window anymore and don't delete it. bool RemoveTrackedWindow(wxWindow *win); --- 574,582 ---- // Add a wxWindow to track and delete when we're closed, only track ! // the parent window, not it's children. returns true if it was added. ! // Note: wxObject is used as the base class since we blindly call this ! // function for all objects with classinfo in the bindings and we ! // want to minimize the code in the bindings. ! bool AddTrackedWindow(wxObject *win); // Don't track this window anymore and don't delete it. bool RemoveTrackedWindow(wxWindow *win); *************** *** 559,563 **** // delete all stray wxWindow derived classes that have been destroyed ! // by wxWidgets (eg. a child window) (not needed, for debugging perhaps?) void GarbageCollectWindows(bool closeWindows); --- 585,590 ---- // delete all stray wxWindow derived classes that have been destroyed ! // by wxWidgets (eg. a child window) ! // This function does not need to be called ever, for debugging perhaps? void GarbageCollectWindows(bool closeWindows); *************** *** 587,591 **** // Push the errorMsg on the stack and call lua_error void terror(const char *errorMsg) const; ! wxLUA_UNUSED_NOTUNICODE(void terror(const wxString& errorMsg) const { terror(wx2lua(errorMsg)); }) // Push the object u onto the top of the stack wrapped in a newuserdata // with it's metatable set to the table from tget(tag). Returns true if the --- 614,618 ---- // Push the errorMsg on the stack and call lua_error void terror(const char *errorMsg) const; ! wxLUA_UNICODE_ONLY(void terror(const wxString& errorMsg) const { terror(wx2lua(errorMsg)); }) // Push the object u onto the top of the stack wrapped in a newuserdata // with it's metatable set to the table from tget(tag). Returns true if the *************** *** 646,653 **** // calls terror if the value is not of the right type. bool GetBooleanType(int stack_idx); ! // Validate that the object at the stack index specified is a enumeration object ! // or that the object can be converted to a enumeration and return the enumeration value. // calls terror if the value is not of the right type. ! long GetEnumerationType(int stack_idx); // Validate that the object at the stack index specified is a number object // or that the object can be converted to a number and return the number value. --- 673,680 ---- // calls terror if the value is not of the right type. bool GetBooleanType(int stack_idx); ! // Validate that the object at the stack index specified is an integer object ! // or that the object can be converted to an integer and return the integer value. // calls terror if the value is not of the right type. ! long GetIntegerType(int stack_idx); // Validate that the object at the stack index specified is a number object // or that the object can be converted to a number and return the number value. *************** *** 659,663 **** bool IsStringType(int stack_idx) const; bool IsBooleanType(int stack_idx) const; ! bool IsEnumerationType(int stack_idx) const; bool IsNumberType(int stack_idx) const; --- 686,690 ---- bool IsStringType(int stack_idx) const; bool IsBooleanType(int stack_idx) const; ! bool IsIntegerType(int stack_idx) const; bool IsNumberType(int stack_idx) const; *************** *** 707,710 **** --- 734,739 ---- // userdata and the new wxLuaObject wraps the lua function or value // which will be deleted by this. + // The derived methods are stored in the "wxLuaDerivedMethods" table in the + // lua registry table. bool SetDerivedMethod(void *pObject, const char *method_name, wxLuaObject* wxlObj); // Is there a derived method given an object and and a method name. *************** *** 713,720 **** bool HasDerivedMethod(void *pObject, const char *method_name, bool push_method) const; // When an object is being garbage collected and we call RemoveTrackedObject ! // object on it, we should also remove any derived functions or values it may have bool RemoveDerivedMethod(void *pObject) const; // Find a derived method given an object and and a method name. ! // If the method can be found, return the wxLuaState it belongs to. static wxLuaState GetDerivedMethodState(void *pObject, const char *method); --- 742,753 ---- bool HasDerivedMethod(void *pObject, const char *method_name, bool push_method) const; // When an object is being garbage collected and we call RemoveTrackedObject ! // object on it, we should also remove any derived functions or values it may have. bool RemoveDerivedMethod(void *pObject) const; // Find a derived method given an object and and a method name. ! // If the method can be found, return the valid wxLuaState it belongs to. ! // This function can be used for classes that implement virtual functions to ! // try to find a wxLuaState that may have overridden the function to call it. ! // It is probably easier to merely make a wxLuaState a class member for ! // faster lookup though. static wxLuaState GetDerivedMethodState(void *pObject, const char *method); *************** *** 742,746 **** bool lua_IsString(int index) const; bool lua_IsCFunction(int index) const; ! bool lua_IsUserData(int index) const; int lua_Type(int index) const; wxString lua_TypeName(int type) const; --- 775,779 ---- bool lua_IsString(int index) const; bool lua_IsCFunction(int index) const; ! bool lua_IsUserdata(int index) const; int lua_Type(int index) const; wxString lua_TypeName(int type) const; *************** *** 758,762 **** size_t luaL_ObjLen(int index) const; lua_CFunction lua_ToCFunction(int index) const; ! void* lua_ToUserData(int index) const; wxLuaState lua_ToThread(int index) const; const void* lua_ToPointer(int index) const; --- 791,795 ---- size_t luaL_ObjLen(int index) const; lua_CFunction lua_ToCFunction(int index) const; ! void* lua_ToUserdata(int index) const; wxLuaState lua_ToThread(int index) const; const void* lua_ToPointer(int index) const; *************** *** 770,779 **** void lua_PushLString(const char* s, size_t len); void lua_PushString(const char* s); ! wxLUA_UNUSED_NOTUNICODE(void lua_PushString(const wxString& s) { lua_PushString(wx2lua(s)); }) //wxString lua_PushVfString(); //wxString lua_PushFString(); void lua_PushCClosure(lua_CFunction fn, int n); void lua_PushBoolean(bool b); ! void lua_PushLightUserData(void* p); //void lua_PushThread(lua_State* L); --- 803,812 ---- void lua_PushLString(const char* s, size_t len); void lua_PushString(const char* s); ! wxLUA_UNICODE_ONLY(void lua_PushString(const wxString& s) { lua_PushString(wx2lua(s)); }) //wxString lua_PushVfString(); //wxString lua_PushFString(); void lua_PushCClosure(lua_CFunction fn, int n); void lua_PushBoolean(bool b); ! void lua_PushLightUserdata(void* p); //void lua_PushThread(lua_State* L); *************** *** 783,793 **** void lua_GetTable(int idx); void lua_GetField(int idx, const char* k); ! wxLUA_UNUSED_NOTUNICODE(void lua_GetField(int idx, const wxString& k) { lua_GetField(idx, wx2lua(k)); }) void lua_RawGet(int idx); void lua_RawGeti(int idx, int n); void lua_CreateTable(int narr, int nrec); void lua_NewTable(); ! void* lua_NewUserData(size_t sz); ! int lua_GetMetaTable(int objindex); void lua_GetFenv(int idx); --- 816,826 ---- void lua_GetTable(int idx); void lua_GetField(int idx, const char* k); ! wxLUA_UNICODE_ONLY(void lua_GetField(int idx, const wxString& k) { lua_GetField(idx, wx2lua(k)); }) void lua_RawGet(int idx); void lua_RawGeti(int idx, int n); void lua_CreateTable(int narr, int nrec); void lua_NewTable(); ! void* lua_NewUserdata(size_t sz); ! int lua_GetMetatable(int objindex); void lua_GetFenv(int idx); *************** *** 797,804 **** void lua_SetTable(int idx); void lua_SetField(int idx, const char* k); ! wxLUA_UNUSED_NOTUNICODE(void lua_SetField(int idx, const wxString& k) { lua_SetField(idx, wx2lua(k)); }) void lua_RawSet(int idx); void lua_RawSeti(int idx, int n); ! int lua_SetMetaTable(int objindex); int lua_SetFenv(int idx); --- 830,837 ---- void lua_SetTable(int idx); void lua_SetField(int idx, const char* k); ! wxLUA_UNICODE_ONLY(void lua_SetField(int idx, const wxString& k) { lua_SetField(idx, wx2lua(k)); }) void lua_RawSet(int idx); void lua_RawSeti(int idx, int n); ! int lua_SetMetatable(int objindex); int lua_SetFenv(int idx); *************** *** 810,814 **** int lua_CPCall(lua_CFunction func, void *ud); int lua_Load(lua_Reader reader, void *dt, const char* chunkname); ! wxLUA_UNUSED_NOTUNICODE(int lua_Load(lua_Reader reader, void *dt, const wxString& chunkname) { return lua_Load(reader, dt, wx2lua(chunkname)); }) int lua_Dump(lua_Writer writer, void *data); --- 843,847 ---- int lua_CPCall(lua_CFunction func, void *ud); int lua_Load(lua_Reader reader, void *dt, const char* chunkname); ! wxLUA_UNICODE_ONLY(int lua_Load(lua_Reader reader, void *dt, const wxString& chunkname) { return lua_Load(reader, dt, wx2lua(chunkname)); }) int lua_Dump(lua_Writer writer, void *data); *************** *** 845,854 **** void lua_Register(const char* funcName, lua_CFunction f); ! wxLUA_UNUSED_NOTUNICODE(void lua_Register(const wxString& funcName, lua_CFunction f) { lua_Register(wx2lua(funcName), f); }) void lua_PushCFunction(lua_CFunction f); bool lua_IsFunction(int idx) const; bool lua_IsTable(int idx) const; ! bool lua_IsLightUserData(int idx) const; bool lua_IsNil(int idx) const; bool lua_IsBoolean(int idx) const; --- 878,887 ---- void lua_Register(const char* funcName, lua_CFunction f); ! wxLUA_UNICODE_ONLY(void lua_Register(const wxString& funcName, lua_CFunction f) { lua_Register(wx2lua(funcName), f); }) void lua_PushCFunction(lua_CFunction f); bool lua_IsFunction(int idx) const; bool lua_IsTable(int idx) const; ! bool lua_IsLightUserdata(int idx) const; bool lua_IsNil(int idx) const; bool lua_IsBoolean(int idx) const; *************** *** 867,875 **** int lua_GetStack(int level, lua_Debug* ar); int lua_GetInfo(const char* what, lua_Debug* ar); ! wxLUA_UNUSED_NOTUNICODE(int lua_GetInfo(const wxString& what, lua_Debug* ar) { return lua_GetInfo(wx2lua(what), ar); }) const char* lua_GetLocal(const lua_Debug* ar, int n); const char* lua_SetLocal(const lua_Debug* ar, int n); ! const char* lua_GetUpValue(int funcindex, int n); ! const char* lua_SetUpValue(int funcindex, int n); int lua_SetHook(lua_Hook func, int mask, int count); --- 900,908 ---- int lua_GetStack(int level, lua_Debug* ar); int lua_GetInfo(const char* what, lua_Debug* ar); ! wxLUA_UNICODE_ONLY(int lua_GetInfo(const wxString& what, lua_Debug* ar) { return lua_GetInfo(wx2lua(what), ar); }) const char* lua_GetLocal(const lua_Debug* ar, int n); const char* lua_SetLocal(const lua_Debug* ar, int n); ! const char* lua_GetUpvalue(int funcindex, int n); ! const char* lua_SetUpvalue(int funcindex, int n); int lua_SetHook(lua_Hook func, int mask, int count); *************** *** 883,887 **** void luaI_OpenLib(const char *libname, const luaL_reg *l, int nup); void luaL_Register(const char *libname, const luaL_reg *l); ! int luaL_GetMetaField(int obj, const char *e); int luaL_CallMeta(int obj, const char *e); int luaL_TypeError(int narg, const char *tname); --- 916,920 ---- void luaI_OpenLib(const char *libname, const luaL_reg *l, int nup); void luaL_Register(const char *libname, const luaL_reg *l); ! int luaL_GetMetafield(int obj, const char *e); int luaL_CallMeta(int obj, const char *e); int luaL_TypeError(int narg, const char *tname); *************** *** 900,904 **** int luaL_NewMetatable(const char *tname); void luaL_GetMetatable(const char *tname); ! void *luaL_CheckUData(int ud, const char *tname); void luaL_Where(int lvl); --- 933,937 ---- int luaL_NewMetatable(const char *tname); void luaL_GetMetatable(const char *tname); ! void *luaL_CheckUdata(int ud, const char *tname); void luaL_Where(int lvl); |