From: John L. <jr...@us...> - 2008-01-03 00:06:01
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv27681/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlcallb.h Log Message: Change wxLuaEventCallback so it doesn't connect in the constructor to allow deleting it if it fails before calling lua_error() and it's long jmp. Renamed the event handler functions to OnEvent() to match the wxWidgets semantics. Index: wxlcallb.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlcallb.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** wxlcallb.h 22 Dec 2007 06:07:15 -0000 1.26 --- wxlcallb.h 3 Jan 2008 00:05:58 -0000 1.27 *************** *** 15,29 **** // ---------------------------------------------------------------------------- ! // wxLuaEventCallback - Forward events from C++ wxWidgets wxEvtHandlers to Lua functions // // The wxLuaEventCallback is created with the wxLuaState, the stack index of a // Lua function to call when a wxEvent is received, the window id ranges, and ! // the wxEventType to connect using wxEvtHandler::Connect() with this as the // callback user data for event. // ! // Do NOT delete this, the wxEvtHandler deletes the callback user data itself. // ! // The function EventHandler() generically handles the events and forwards them ! // to the event's wxLuaEventCallback callback user data function CallFunction(). // ---------------------------------------------------------------------------- --- 15,31 ---- // ---------------------------------------------------------------------------- ! // wxLuaEventCallback - Forward events from wxEvtHandlers to Lua functions. // // The wxLuaEventCallback is created with the wxLuaState, the stack index of a // Lua function to call when a wxEvent is received, the window id ranges, and ! // the wxEventType used with wxEvtHandler::Connect() with this as the // callback user data for event. // ! // Do NOT delete wxLuaEventCallbacks since the wxEvtHandler deletes the ! // callback user data itself. // ! // The function wxLuaEventCallback::OnAllEvents() generically handles all wxEvents ! // by retrieving the wxLuaEventCallback instance from the wxEvent userdata ! // to call wxLuaEventCallback::OnEvent() on the correct instance. // ---------------------------------------------------------------------------- *************** *** 34,45 **** { public: ! // winID and lastID follow the same notation as wxEvtHandler::Connect ! // if only one event Id is needed set lastId = wxID_ANY ! wxLuaEventCallback( const wxLuaState& wxlState, int lua_func_stack_idx, ! wxWindowID win_id, wxWindowID last_id, ! wxEventType eventType, wxEvtHandler *evtHandler ); virtual ~wxLuaEventCallback(); void ClearwxLuaState(); // m_wxlState.UnRef() --- 36,56 ---- { public: ! // default constructor, call Connect() to actually connect the event ! wxLuaEventCallback(); virtual ~wxLuaEventCallback(); + // Verifies the inputs and calls evtHandler->Connect() with this as + // the callback userdata. + // lua_func_stack_idx is the Lua stack index of a function to call with + // the wxEvent as the single parameter. + // win_id and last_id follow the same notation as wxEvtHandler::Connect(). + // If only one event Id is needed set last_id = wxID_ANY + // Returns an empty string on success and the wxEvtHandler takes ownership of this, + // otherwise an error message and you must delete this since nobody else will. + virtual wxString Connect( const wxLuaState& wxlState, int lua_func_stack_idx, + wxWindowID win_id, wxWindowID last_id, + wxEventType eventType, wxEvtHandler *evtHandler ); + void ClearwxLuaState(); // m_wxlState.UnRef() *************** *** 49,53 **** wxEventType GetEventType() const { return m_wxlBindEvent ? *m_wxlBindEvent->eventType : wxEVT_NULL; } wxEvtHandler* GetEvtHandler() const { return m_evtHandler; } ! int GetLuaRoutine() const { return m_routine; } const wxLuaBindEvent* GetwxLuaBindEvent() const { return m_wxlBindEvent; } --- 60,64 ---- wxEventType GetEventType() const { return m_wxlBindEvent ? *m_wxlBindEvent->eventType : wxEVT_NULL; } wxEvtHandler* GetEvtHandler() const { return m_evtHandler; } ! int GetLuaFuncRef() const { return m_luafunc_ref; } const wxLuaBindEvent* GetwxLuaBindEvent() const { return m_wxlBindEvent; } *************** *** 57,72 **** wxString GetInfo() const; // Get a human readable string ! // Central event handler that calls CallFunction() for the actual ! // wxLuaEventCallback 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 wxlua_lreg_refs_key registry table ! wxLuaState m_wxlState; // store it since we're added to a list of its callbacks. wxEvtHandler* m_evtHandler; wxWindowID m_id; --- 68,83 ---- wxString GetInfo() const; // Get a human readable string ! // Central event handler that calls OnEvent() for the actual ! // wxLuaEventCallback callback userdata. This function is treated like a // static function that all handlers of this class will call. ! void OnAllEvents(wxEvent& event); ! // Handle the wxEvent by calling the Lua function to handle the event. ! // The Lua function will receive a single parameter, the wxEvent. ! virtual void OnEvent(wxEvent *event); protected: ! int m_luafunc_ref; // ref to the Lua routine to call in the wxlua_lreg_refs_key registry table ! wxLuaState m_wxlState; // store it since we're added to a list of its callbacks. wxEvtHandler* m_evtHandler; wxWindowID m_id; *************** *** 83,92 **** // Clears the metatable for the wxWindow userdata so that after a call to // win:Destroy() calling a function on win won't crash wxLua, but will generate ! // an error in Lua. // // Do NOT delete this, the wxEvtHandler deletes the callback user data itself. // ! // The function EventHandler() generically handles the events and forwards them ! // to the event's wxLuaWinDestroyCallback callback user data function OnDestroy(). // ---------------------------------------------------------------------------- --- 94,103 ---- // Clears the metatable for the wxWindow userdata so that after a call to // win:Destroy() calling a function on win won't crash wxLua, but will generate ! // an error message in Lua. // // Do NOT delete this, the wxEvtHandler deletes the callback user data itself. // ! // The function OnAllDestroyEvents() generically handles the events and forwards them ! // to the wxEvent's wxLuaWinDestroyCallback callback user data function OnDestroy(). // ---------------------------------------------------------------------------- *************** *** 94,98 **** { public: ! wxLuaWinDestroyCallback(const wxLuaState& state, wxWindow *win, int iTag); virtual ~wxLuaWinDestroyCallback(); --- 105,109 ---- { public: ! wxLuaWinDestroyCallback(const wxLuaState& state, wxWindow *win); virtual ~wxLuaWinDestroyCallback(); *************** *** 110,114 **** // wxLuaWinDestroyCallback callback user data. This function is treated like a // static function that all handlers of this class will call. ! void EventHandler(wxWindowDestroyEvent& event); // Handle the event by clearing the metatable for the window --- 121,125 ---- // wxLuaWinDestroyCallback callback user data. This function is treated like a // static function that all handlers of this class will call. ! void OnAllDestroyEvents(wxWindowDestroyEvent& event); // Handle the event by clearing the metatable for the window Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** wxlbind.h 22 Dec 2007 06:07:15 -0000 1.75 --- wxlbind.h 3 Jan 2008 00:05:58 -0000 1.76 *************** *** 24,33 **** // Binding wxLua types are positive integers generated automatically when initialized ! // so the inbuilt wxLua types (WXLUA_TXXX) corresponding to Lua types // (LUA_TXXX) are negative values. // *Use the function bool wxlua_iswxuserdatatype(wxl_type) if you want to // differentiate between the two. // ! // Note that WXLUA_TUNKNOWN is use as initialiser for class types // and is used as an end marker for the wxLuaArgType array that // represents function prototype argument types in the wxLuaBindCFunc struct. --- 24,33 ---- // Binding wxLua types are positive integers generated automatically when initialized ! // and the inbuilt wxLua types (WXLUA_TXXX) corresponding to Lua types // (LUA_TXXX) are negative values. // *Use the function bool wxlua_iswxuserdatatype(wxl_type) if you want to // differentiate between the two. // ! // Note that WXLUA_TUNKNOWN is used as an initialiser for class types // and is used as an end marker for the wxLuaArgType array that // represents function prototype argument types in the wxLuaBindCFunc struct. *************** *** 52,60 **** // Blindly convert the lua_type to the wxlua_type. Note: WXLUA_TXXX = -1*LUA_TXXX - 2 ! // *** See wxlua_luatowxluatype() for better function *** #define LUAT_TO_WXLUAT(luatype) (-1*(luatype) - 2) // Variables used in the wxLuaArgType member of the wxLuaBindCFunc for ! // Lua types. The binding generator will use these and generate new ones for // classes and structs as specified in the bindings. extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatype_TNONE; --- 52,60 ---- // Blindly convert the lua_type to the wxlua_type. Note: WXLUA_TXXX = -1*LUA_TXXX - 2 ! // *** See wxlua_luatowxluatype() for a better function *** #define LUAT_TO_WXLUAT(luatype) (-1*(luatype) - 2) // Variables used in the wxLuaArgType member of the wxLuaBindCFunc for ! // Lua types. The binding generator uses these and generates new ones for // classes and structs as specified in the bindings. extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatype_TNONE; *************** *** 71,75 **** extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatype_TCFUNCTION; ! // copies of wxLua types for binding types that are used very often extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_NULL; // wxLua type for NULL pointer extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_wxEvent; // wxLua type for wxEvents --- 71,77 ---- extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatype_TCFUNCTION; ! // Copies of wxLua types that are used very often. ! // Note that we do not use the original since we may not be linked ! // to the binding library that defines them. extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_NULL; // wxLua type for NULL pointer extern WXDLLIMPEXP_DATA_WXLUA(int) g_wxluatag_wxEvent; // wxLua type for wxEvents *************** *** 81,85 **** // ---------------------------------------------------------------------------- ! // wxLuaBindCFunc and friends - Defines a single C func for a LUA method // ---------------------------------------------------------------------------- --- 83,87 ---- // ---------------------------------------------------------------------------- ! // wxLuaArgType a pointer to a declared wxLua type, see wxLuaBindCFunc::argtypes // ---------------------------------------------------------------------------- *************** *** 87,91 **** extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgType) g_wxluaargtypeArray_None[1]; // = {0} ! // Values for the wxLuaBindMethod::type and wxLuaBindCFunc::type enum wxLuaMethod_Type { --- 89,95 ---- extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgType) g_wxluaargtypeArray_None[1]; // = {0} ! // ---------------------------------------------------------------------------- ! // wxLuaMethod_Type: Values for the wxLuaBindMethod::method_type and wxLuaBindCFunc::method_type ! // ---------------------------------------------------------------------------- enum wxLuaMethod_Type { *************** *** 112,115 **** --- 116,123 ---- }; + // ---------------------------------------------------------------------------- + // wxLuaBindCFunc - Defines a single function for wxLua + // ---------------------------------------------------------------------------- + struct WXDLLIMPEXP_WXLUA wxLuaBindCFunc { *************** *** 117,126 **** int method_type; // enum wxLuaMethod_Type flags for this function int minargs; // Min number of required args ! int maxargs; // Total number of args allowed wxLuaArgType* argtypes; // Array of wxLua types representing each argument, zero terminated. }; // ---------------------------------------------------------------------------- ! // wxLuaBindMethod - Defines a LUA method or property // ---------------------------------------------------------------------------- --- 125,134 ---- int method_type; // enum wxLuaMethod_Type flags for this function int minargs; // Min number of required args ! int maxargs; // Max number of args allowed wxLuaArgType* argtypes; // Array of wxLua types representing each argument, zero terminated. }; // ---------------------------------------------------------------------------- ! // wxLuaBindMethod - Defines a method or property (a function) for wxLua // ---------------------------------------------------------------------------- *************** *** 183,205 **** // ---------------------------------------------------------------------------- ! // wxLuaBindClass - Defines a LUA C++ class interface // ---------------------------------------------------------------------------- struct WXDLLIMPEXP_WXLUA wxLuaBindClass { ! const char* name; // Name of the class ! wxLuaBindMethod* wxluamethods; // Pointer to methods for this class ! int wxluamethods_n; // Number of methods ! wxClassInfo* classInfo; // Pointer to the wxClassInfo associated with this class or NULL. ! int* wxluatype; // wxLua class type for userdata ! const char* baseclassName; // Name of base class, or NULL if none. ! wxLuaBindClass* baseclass; // Pointer to the base class or NULL for none. ! // This member is set after all the bindings are ! // registered since the base class may be from ! // a different module (a library perhaps). ! // See wxLuaBinding::SetBaseClass() ! wxLuaBindNumber* enums; // Class member enums or NULL if none ! int enums_n; // number of enums }; --- 191,213 ---- // ---------------------------------------------------------------------------- ! // wxLuaBindClass - Defines a C++ class or struct for wxLua // ---------------------------------------------------------------------------- struct WXDLLIMPEXP_WXLUA wxLuaBindClass { ! const char* name; // Name of the class or struct ! wxLuaBindMethod* wxluamethods; // Pointer to methods for this class ! int wxluamethods_n; // Number of methods ! wxClassInfo* classInfo; // Pointer to the wxClassInfo associated with this class or NULL. ! int* wxluatype; // wxLua class type for userdata ! const char* baseclassName; // Name of base class, or NULL if none. ! wxLuaBindClass* baseclass; // Pointer to the base class or NULL for none. ! // This member is set after all the bindings are ! // registered since the base class may be from ! // a different module (a library perhaps). ! // See wxLuaBinding::SetBaseClass() ! wxLuaBindNumber* enums; // Class member enums or NULL if none ! int enums_n; // number of enums }; *************** *** 221,225 **** // ---------------------------------------------------------------------------- ! // Central function to call for overloaded functions // ---------------------------------------------------------------------------- --- 229,233 ---- // ---------------------------------------------------------------------------- ! // Overloaded binding function call helper functions. // ---------------------------------------------------------------------------- *************** *** 236,243 **** // ---------------------------------------------------------------------------- ! // wxLuaObject - wraps a reference to a Lua object reference inside a ! // wxObject-derived class so that a Lua object can be used for ! // user data, and also with a simple extension by a proxy member ! // value it can be used to provide pointers to the wxValidator classes. // ---------------------------------------------------------------------------- --- 244,251 ---- // ---------------------------------------------------------------------------- ! // wxLuaObject - Wraps a reference to a Lua object reference inside a ! // wxObject-derived class so that a Lua object can be used for userdata. ! // Also with a simple extension by a proxy member value it can be used ! // to provide pointers to the wxValidator classes. // ---------------------------------------------------------------------------- *************** *** 287,291 **** wxLuaState GetwxLuaState() const; ! private: wxLuaState* m_wxlState; // a pointer due to #include recursion. int m_reference; // reference in wxlua_lreg_refs_key registry table --- 295,299 ---- wxLuaState GetwxLuaState() const; ! protected: wxLuaState* m_wxlState; // a pointer due to #include recursion. int m_reference; // reference in wxlua_lreg_refs_key registry table *************** *** 301,304 **** --- 309,313 ---- }; + private: DECLARE_ABSTRACT_CLASS(wxLuaObject) }; *************** *** 339,343 **** // ---------------------------------------------------------------------------- // wxLuaSmartStringArray - Wraps a "new" array of wxStrings with an automatic ! // destructor to delete them to make binding easier // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaSmartStringArray --- 348,352 ---- // ---------------------------------------------------------------------------- // wxLuaSmartStringArray - Wraps a "new" array of wxStrings with an automatic ! // destructor that deletes them to make binding easier. // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaSmartStringArray *************** *** 356,360 **** // ---------------------------------------------------------------------------- // wxLuaSmartIntArray - Wraps a "new" array of ints with an automatic ! // destructor to delete them to make binding easier. // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaSmartIntArray --- 365,369 ---- // ---------------------------------------------------------------------------- // wxLuaSmartIntArray - Wraps a "new" array of ints with an automatic ! // destructor that deletes them to make binding easier. // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaSmartIntArray *************** *** 373,377 **** // ---------------------------------------------------------------------------- // wxLuaSmartwxArrayString - Wraps a "new" wxArrayString with an automatic ! // destructor to delete them to make binding easier // ---------------------------------------------------------------------------- --- 382,386 ---- // ---------------------------------------------------------------------------- // wxLuaSmartwxArrayString - Wraps a "new" wxArrayString with an automatic ! // destructor that deletes them to make binding easier. // ---------------------------------------------------------------------------- *************** *** 399,403 **** // ---------------------------------------------------------------------------- // wxLuaSmartwxSortedArrayString - Wraps a "new" wxSortedArrayString with an automatic ! // destructor to delete them to make binding easier // ---------------------------------------------------------------------------- --- 408,412 ---- // ---------------------------------------------------------------------------- // wxLuaSmartwxSortedArrayString - Wraps a "new" wxSortedArrayString with an automatic ! // destructor that deletes them to make binding easier. // ---------------------------------------------------------------------------- |