From: John L. <jr...@us...> - 2005-12-30 04:36:08
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11092/wxLua/modules/wxlua/include Modified Files: internal.h wxlintrp.h wxlstate.h Log Message: use wxLuaState in addToTrackedMemory, now called wxLua_addToTrackedMemory better docs in wxlstate header rem out wxPrintf debug code fix error recreating wxLuaState, need to Destroy before calling UnRef Index: wxlintrp.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlintrp.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** wxlintrp.h 22 Dec 2005 18:42:35 -0000 1.5 --- wxlintrp.h 30 Dec 2005 04:35:59 -0000 1.6 *************** *** 34,52 **** //----------------------------------------------------------------------------- // wxLuaInterpreter - // - // notes : create instance, call RunString("some lua code") - // Events are sent to the evthander if !null with the given id # //----------------------------------------------------------------------------- ! typedef class wxLuaState wxLuaInterpreter; ! ! ! /* ! ! ! // ----------------------------------------------------------------------- ! // implementation ! ! */ //----------------------------------------------------------------------------- --- 34,40 ---- //----------------------------------------------------------------------------- // wxLuaInterpreter //----------------------------------------------------------------------------- ! typedef class wxLuaState wxLuaInterpreter; // depricated - use wxLuaState instead //----------------------------------------------------------------------------- Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** wxlstate.h 22 Dec 2005 19:52:50 -0000 1.13 --- wxlstate.h 30 Dec 2005 04:35:59 -0000 1.14 *************** *** 120,124 **** // destroy and cleanup the lua_State, returns success ! // if 'force' then make sure all wxWindows are destroyed. bool CloseLuaState(bool force); // Free up the tracked resources list. --- 120,124 ---- // destroy and cleanup the lua_State, returns success ! // if 'force' = true then make sure all wxWindows are destroyed. bool CloseLuaState(bool force); // Free up the tracked resources list. *************** *** 129,136 **** void UnRegisterBindings(); ! lua_State *m_lua_State; ! bool m_lua_State_static; ! wxLuaBindingList m_bindings; // A list of generated lua bindings bool m_typesRegistered; // Is the binding registered --- 129,138 ---- void UnRegisterBindings(); ! // ------------------------------------------------------------------------ ! lua_State *m_lua_State; // the lua_State that "is" lua ! bool m_lua_State_static; // lua_close the lua_State if !static ! ! wxLuaBindingList m_bindings; // A wxList of generated lua bindings bool m_typesRegistered; // Is the binding registered *************** *** 162,169 **** int m_lua_debug_hook; ! wxEvtHandler *m_evtHandler; // event handler to send events to wxWindowID m_id; // event id to send the events with static wxLuaStateRefData* GetLuaStateRefData(lua_State* L); static wxHashMapLuaStateRefData s_wxHashMapLuaStateRefData; --- 164,174 ---- int m_lua_debug_hook; ! wxEvtHandler *m_evtHandler; // event handler to send wxLuaEvents to wxWindowID m_id; // event id to send the events with + // 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 static wxHashMapLuaStateRefData s_wxHashMapLuaStateRefData; *************** *** 190,198 **** --- 195,211 ---- { public: + // Default constructor or if create=true then create a new lua_State + // and add all the bindings wxLuaState(bool create = false) : wxObject() { if (create) Create(); } + // Create a new lua_State, add the bindings, and set the event handler + // and wxWindowID to send the wxLuaEvents to wxLuaState(wxEvtHandler *handler, wxWindowID id = wxID_ANY) : wxObject() { Create(handler, id); } + // Create a wxLuaState from an existing lua_State wxLuaState(lua_State* L, wxLuaState_Type type = WXLUASTATE_ATTACH) { Create(L, type); } + // Copy constructor, refs existing wxLuaState wxLuaState(const wxLuaState& wxlState) { Create(wxlState); } + // ALWAYS destroy lua_State before calling UnRef, else circular + // destruction since ref count goes to 0 before actually destroying the lua_State virtual ~wxLuaState() { Destroy(); } *************** *** 215,219 **** void Destroy(); // Close the lua_State and if 'force' close all attached wxWindows ! // if not force then popup dialog to ask if windows should be destroyed. bool CloseLuaState(bool force); --- 228,232 ---- void Destroy(); // Close the lua_State and if 'force' close all attached wxWindows ! // if !force then popup a dialog to ask if windows should be destroyed. bool CloseLuaState(bool force); *************** *** 223,245 **** wxLuaStateRefData* GetLuaStateRefData() const { return (wxLuaStateRefData*)GetRefData(); } ! // Get the wxEventType currently wxEventType GetInEventType() const; // ----------------------------------------------------------------------- ! // Set the event handler that the events will be sent to, can be null void SetEventHandler(wxEvtHandler *evtHandler); wxEvtHandler *GetEventHandler() const; ! ! // Get/Set the id that the events will be sent with void SetId(wxWindowID id); ! wxWindowID GetId() const; ! ! // generic function to generate a wxEVT_LUA_ERROR with the string message ! void DisplayError( const wxString &errorMsg ); ! ! // checks return val of 'lua_load' and `lua_pcall', if error send wxEVT_LUA_ERROR ! bool CheckRunError(int rc); void SendEvent( wxLuaEvent &event ) const; --- 236,259 ---- wxLuaStateRefData* GetLuaStateRefData() const { return (wxLuaStateRefData*)GetRefData(); } ! // Get the wxEventType that lua may currently be in, wxEVT_NULL if not in an ! // event handler. Be careful about destroying lua when in an event handler. wxEventType GetInEventType() const; // ----------------------------------------------------------------------- ! // Set the event handler that the events from this will be sent to, can be null void SetEventHandler(wxEvtHandler *evtHandler); wxEvtHandler *GetEventHandler() const; ! // Get/Set the wxWindowID that the events will be sent with void SetId(wxWindowID id); ! wxWindowID GetId() const; + // generic function to generate and send a wxEVT_LUA_ERROR with the string message + void SendErrorEvent( const wxString &errorMsg ); + // checks return val of 'lua_load' and `lua_pcall', using CheckRunError and + // if error send wxEVT_LUA_ERROR returns false if there was an error + bool CheckAndSendRunErrorEvent(int rc); + // Sends an event, after checking that this is valid, to the set + // wxEventHandler (see SetEventHandler) which may be NULL. void SendEvent( wxLuaEvent &event ) const; *************** *** 248,268 **** // Run a lua file int RunFile(const wxString &fileName); ! // Run a string that contains lua code int RunString(const wxString &script, const wxString& name = wxEmptyString); ! // Run a char array #include(d) from bin2c compilation int RunBuffer(const unsigned char buf[], size_t size, const wxString &name = wxT("= lua")); ! // Is a program running now bool IsRunning() const; ! // Break a currently running lua program ! void DebugHookBreak(const wxString &message = wxT("Interpreter stopped")); ! wxDEPRECATED( void Break(const wxString &message = wxT("Interpreter stopped")) { DebugHookBreak(message); } ); ! // has Break() been called bool GetDebugHookBreak() const; wxString GetDebugHookBreakMessage() const; - unsigned long GetLastLuaDebugHookTime() const; - void SetLastLuaDebugHookTime(unsigned long t); - // ----------------------------------------------------------------------- --- 262,282 ---- // Run a lua file int RunFile(const wxString &fileName); ! // Run a string that contains lua code using lua_dostring int RunString(const wxString &script, const wxString& name = wxEmptyString); ! // Run a char array #included from bin2c compilation int RunBuffer(const unsigned char buf[], size_t size, const wxString &name = wxT("= lua")); ! // Is a program running now, running state is set for Run/File/String/Buffer bool IsRunning() const; ! ! // Break a currently running lua program by setting the lua debug hook to ! // be called for anything and breaking as soon as possible ! void DebugHookBreak(const wxString &message = wxT("Lua interpreter stopped")); ! wxDEPRECATED( void Break(const wxString &message = wxT("Lua interpreter stopped")) { DebugHookBreak(message); } ); ! // has DebugHookBreak() been called and we're waiting for the hook call bool GetDebugHookBreak() const; + // Get the message that will be sent when from a DebugHookBreak call wxString GetDebugHookBreakMessage() const; // ----------------------------------------------------------------------- *************** *** 282,289 **** int GetLuaDebugHook() const; // ----------------------------------------------------------------------- // Binding functions ! // registers a new function for Lua void RegisterFunction(lua_CFunction func, const wxString &funcName); --- 296,309 ---- int GetLuaDebugHook() const; + // Internally updated time that the debug hook was last called when running + // lua code and SetLuaDebugHook is turned on + unsigned long GetLastLuaDebugHookTime() const; + // Set to an arbitrary time to control debug timing + void SetLastLuaDebugHookTime(unsigned long t); + // ----------------------------------------------------------------------- // Binding functions ! // registers a new function for Lua, see usage in wxlstate.cpp void RegisterFunction(lua_CFunction func, const wxString &funcName); *************** *** 293,305 **** wxLuaBinding* GetLuaBinding(const wxString& nameSpace) const; ! const WXLUACLASS * GetLuaClass(int iClassTag); ! const WXLUACLASS * GetLuaClass(const char* className); ! const WXLUACLASS * GetBaseLuaClass(int iClassTag); bool IsDerivedClass(int iClassTag, int iBaseClassTag); ! const WXLUAEVENT * GetLuaEvent(wxEvent *pEvent); void GarbageCollectWindows(bool closeWindows); // Get the binding list used to initialize this class wxLuaBindingList* GetLuaBindingList() const; bool GetTypesRegistered() const; // Is the binding registered --- 313,326 ---- wxLuaBinding* GetLuaBinding(const wxString& nameSpace) const; ! const WXLUACLASS* GetLuaClass(int iClassTag); ! const WXLUACLASS* GetLuaClass(const char* className); ! const WXLUACLASS* GetBaseLuaClass(int iClassTag); bool IsDerivedClass(int iClassTag, int iBaseClassTag); ! const WXLUAEVENT* GetLuaEvent(wxEvent *pEvent); void GarbageCollectWindows(bool closeWindows); // Get the binding list used to initialize this class + // you may add or remove bindings before creation wxLuaBindingList* GetLuaBindingList() const; bool GetTypesRegistered() const; // Is the binding registered *************** *** 312,315 **** --- 333,337 ---- void addToTrackedMemoryList(wxObject *pObject); + void addToTrackedMemoryList(int obj_ptr, wxObject *pObject); bool removeTrackedMemory(void *pObject, bool fDelete = true); *************** *** 628,632 **** { if ( (*this) != wxlState ) ! Ref(wxlState); return *this; } --- 650,654 ---- { if ( (*this) != wxlState ) ! Create(wxlState); return *this; } Index: internal.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/internal.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** internal.h 18 Dec 2005 18:04:38 -0000 1.16 --- internal.h 30 Dec 2005 04:35:59 -0000 1.17 *************** *** 85,94 **** #define wxLUA_DECLARE_ENCAPSULATION(theObject) \ class theObject; \ ! void LUACALL addToTrackedMemoryList(lua_State *, theObject *); \ ! class theObject##Object : public wxObject \ { \ public: \ ! theObject##Object(theObject *p_##theObject); \ ! ~theObject##Object(); \ private: \ theObject *m_p##theObject; \ --- 85,94 ---- #define wxLUA_DECLARE_ENCAPSULATION(theObject) \ class theObject; \ ! void LUACALL wxLua_addToTrackedMemoryList(wxLuaState& wxlState, theObject *); \ ! class theObject##wxLuaObject : public wxObject \ { \ public: \ ! theObject##wxLuaObject(theObject *p_##theObject); \ ! ~theObject##wxLuaObject(); \ private: \ theObject *m_p##theObject; \ *************** *** 96,120 **** #define wxLUA_IMPLEMENT_ENCAPSULATION(theObject) \ ! theObject##Object::theObject##Object(theObject *p##theObject) : \ m_p##theObject(p##theObject) \ { \ } \ ! theObject##Object::~theObject##Object() \ { \ if (m_p##theObject != NULL) \ delete m_p##theObject; \ } \ ! void LUACALL addToTrackedMemoryList(lua_State *L, theObject *p##theObject) \ { \ ! wxLuaState wxlState(L); \ ! wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); \ ! wxlState.GetLuaStateRefData()->m_pTrackedList->Put((int)p##theObject, new theObject##Object(p##theObject)); \ } // Add a wxWidgets object to the list of tracked objects for // garbage collection purposes. ! void LUACALL addToTrackedMemoryList(lua_State *L, wxObject *); ! wxDEPRECATED( bool LUACALL removeTrackedMemory(lua_State *L, void *pObject, bool fDelete = true) ); ! wxDEPRECATED( void LUACALL addToTrackedWindowList(lua_State *L, wxWindow *) ); // ---------------------------------------------------------------------------- --- 96,116 ---- #define wxLUA_IMPLEMENT_ENCAPSULATION(theObject) \ ! theObject##wxLuaObject::theObject##wxLuaObject(theObject *p##theObject) : \ m_p##theObject(p##theObject) \ { \ } \ ! theObject##wxLuaObject::~theObject##wxLuaObject() \ { \ if (m_p##theObject != NULL) \ delete m_p##theObject; \ } \ ! void LUACALL wxLua_addToTrackedMemoryList(wxLuaState& wxlState, theObject *p##theObject) \ { \ ! wxlState.addToTrackedMemoryList((int)p##theObject, new theObject##wxLuaObject(p##theObject)); \ } // Add a wxWidgets object to the list of tracked objects for // garbage collection purposes. ! void LUACALL wxLua_addToTrackedMemoryList(wxLuaState& wxlState, wxObject *); // ---------------------------------------------------------------------------- |