From: John L. <jr...@us...> - 2005-11-25 02:47:02
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26103/wxLua/modules/wxlua/include Added Files: wxlbind.h wxlcallb.h wxldefs.h wxlhandl.h wxlintrp.h wxlstate.h Log Message: added replacements for interp, callback - breaking up internal --- NEW FILE: wxlstate.h --- ///////////////////////////////////////////////////////////////////////////// // Purpose: Interface to wxLua // Author: Ray Gilbert, John Labenski, J Winwood // Created: 14/11/2001 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WXLSTATE_H_ #define _WXLSTATE_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxlstate.h" #endif extern "C" { #include "lua/include/lua.h" #include "lua/include/lualib.h" #include "lua/include/lauxlib.h" // To not include "lua.h" use these //typedef struct lua_State lua_State; //typedef struct lua_Debug lua_Debug; //typedef int (*lua_CFunction)(lua_State *); } #include "wxlua/include/internal.h" class WXDLLIMPEXP_WXLUA wxLuaState; #include "wx/hashmap.h" WX_DECLARE_VOIDPTR_HASH_MAP( wxLuaState *, wxHashMapLuaState ); //---------------------------------------------------------------------------- // wxLuaStateRefData //---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaStateRefData : public wxObjectRefData { public: wxLuaStateRefData(); wxLuaStateRefData( const wxLuaStateRefData& data ); virtual ~wxLuaStateRefData(); // clear all wxLuaCallbacks on destruction void ClearCallbacks(); lua_State *m_lua_State; wxLuaBindingList m_bindings; // A list of generated lua bindings bool m_typesRegistered; // Is the binding registered int m_startTag; // The first wxLua allocated lua tag int m_lastTag; // The last wxLua lua tag of registered classes int m_functionTag; // The lua tag for function objects. int m_wxLuaTable; // The lua tag for the wxLua private tables int m_wxLuaNull; // The lua tag for wxLuaNull (for NULL pointers) int m_wxDeleteTable; // The lua tag for the wxWindow destroy tracking table wxEventType m_inEventType; // wxEventType set when in event, else -1 wxHashTable *m_pDerivedList; // The list of derived objects. wxHashTable *m_pTrackedList; // The list of tracked objects. wxList *m_pAppHandlerList; // The list of event objects associated with the application object wxList *m_pDestroyHandlerList; // The list of wxLuaDestroyCallbacks installed wxList *m_pWindowList; // The list of all wxWindow objects, wxWidgets will delete these // but for an embedded program they must be deleted before // deleting shutting down the interpreter, else they dangle // used in ~wxLuaInterpreter wxArrayInt m_usedIndexes; static wxHashMapLuaState s_wxHashMapLuaState; private: void Init(); }; //---------------------------------------------------------------------------- // wxLuaState - a ref counted class to interface between C++ and lua's C lua_State //---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaState : public wxObject { public: wxLuaState() : wxObject() {} wxLuaState( const wxLuaState& wxlState ) { Create(wxlState); } virtual ~wxLuaState() {} // Destroy the refed data void Destroy() { UnRef(); } // Is this wxLuaState valid, has refed data bool Ok() const { return m_refData != NULL; } // ----------------------------------------------------------------------- // (re)Create this wxLuaState, unrefing this wxLuaState first. void Create( const wxLuaState& wxlState ); void LUACALL RegisterBindings(bool registerTypes); void LUACALL UnRegisterBindings(); wxLuaBinding* GetLuaBinding(const wxString& nameSpace); 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); // operators bool operator == (const wxLuaState& wxlState) const { return m_refData == wxlState.m_refData; } bool operator != (const wxLuaState& wxlState) const { return m_refData != wxlState.m_refData; } wxLuaState& operator = (const wxLuaState& wxlState) { if ( (*this) != wxlState ) Ref(wxlState); return *this; } private: // ref counting code virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; DECLARE_DYNAMIC_CLASS(wxLuaState) }; #endif // _WXLSTATE_H_ --- NEW FILE: wxldefs.h --- /////////////////////////////////////////////////////////////////////////////// // Name: wxldefs.h // Purpose: wxLua common defines // Author: John Labenski // Modified by: // Created: 5/28/2005 // RCS-ID: // Copyright: (c) John Labenski // Licence: wxWidgets licence /////////////////////////////////////////////////////////////////////////////// #ifndef __WX_WXLDEFS_H__ #define __WX_WXLDEFS_H__ #include "wx/defs.h" extern "C" { typedef struct lua_State lua_State; typedef struct lua_Debug lua_Debug; } // ---------------------------------------------------------------------------- // If you're using stdcall in Lua, then override this with // "LUACALL = __stdcall" in your makefile or project. // ---------------------------------------------------------------------------- #ifndef LUACALL #define LUACALL #endif // ---------------------------------------------------------------------------- // WXDLLIMPEXP macros // ---------------------------------------------------------------------------- // These are our DLL macros (see the contrib libs like wxPlot) #ifdef WXMAKINGDLL_WXLUA #define WXDLLIMPEXP_WXLUA WXEXPORT #define WXDLLIMPEXP_DATA_WXLUA(type) WXEXPORT type #elif defined(WXUSINGDLL) #define WXDLLIMPEXP_WXLUA WXIMPORT #define WXDLLIMPEXP_DATA_WXLUA(type) WXIMPORT type #else // not making nor using DLL #define WXDLLIMPEXP_WXLUA #define WXDLLIMPEXP_DATA_WXLUA(type) type #endif #endif // __WX_WXLDEFS_H__ --- NEW FILE: wxlhandl.h --- //////////////////////////////////////////////////////////////////////////////// // Purpose: wxLuaHandler - Custom Lua Handler // Author: Francis Irving // Created: 16/01/2002 // Modified: J. Winwood. April 2002. Added debugging interfaces // Copyright: (c) 2002 Creature Labs. All rights reserved. // Copyright: (c) 2002 Lomtick Software. All rights reserved. // Licence: wxWidgets licence //////////////////////////////////////////////////////////////////////////////// #ifndef _WXLHANDL_H_ #define _WXLHANDL_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxlhandl.h" #endif #include "wxlua/include/wxldefs.h" #include "wx/utils.h" #include "wx/app.h" class WXDLLIMPEXP_WXLUA wxLuaDebugEvent; class WXDLLIMPEXP_WXLUA wxLuaStackFrame; // ---------------------------------------------------------------------------- // wxLuaHandler - Allow for Custom Lua Handler (an alternative to wxLuaApp) // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaHandler { public: wxLuaHandler(); virtual ~wxLuaHandler(); virtual void AddPendingEvent(wxEvent& event) = 0; virtual bool ProcessEvent(wxEvent& event) = 0; //#if wxUSE_LUASTACKFRAME // virtual void SetStackFrame(wxLuaStackFrame *pStackFrame) = 0; //#endif // wxUSE_LUASTACKFRAME virtual void DisplayError(const wxString &strError) const = 0; void EnterLuaCriticalSection() { m_luaCriticalSection.Enter(); } void LeaveLuaCriticalSection() { m_luaCriticalSection.Leave(); } public: static wxLuaHandler* sm_luahandler; wxCriticalSection m_luaCriticalSection; }; // Lua App/Debugger Interface wxLuaHandler& wxGetLuaHandler(); #endif //_WXLHANDL_H_ --- NEW FILE: wxlcallb.h --- ///////////////////////////////////////////////////////////////////////////// // Purpose: wxLuaCallback and wxLuaDestroyCallback // Author: Francis Irving // Created: 21/01/2002 // Copyright: (c) 2002 Creature Labs. All rights reserved. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WXLCALLB_H_ #define _WXLCALLB_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxlcallb.h" #endif #include "wxlua/include/wxldefs.h" class WXDLLIMPEXP_WXLUA wxLuaStateVariables; // ---------------------------------------------------------------------------- // wxLuaCallback - proxy class to pass a reference to a lua function // through the wxWidgets event system. // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaCallback : public wxEvtHandler { public: wxLuaCallback( lua_State *state, int theRoutine, wxWindowID id, wxEventType eventType, wxEvtHandler *pHandler ); virtual ~wxLuaCallback(); void ClearState() { m_luaState = NULL; } void ClearStateVars() { m_luaStateVars = NULL; } lua_State* GetLuaState() const { return m_luaState; } int GetId() const { return m_id; } wxEventType GetEventType() const { return m_eventType; } wxEvtHandler *GetEvtHandler() const { return m_pHandler; } // central event handler void EventHandler(wxEvent& event); protected: // event handler dispatcher back to Lua void CallFunction(wxEvent *pEvent); // reference to the routine to call int m_routine; // Lua state instance lua_State *m_luaState; // store the state variables since we're added to a list of callbacks. // The lua_State is NULLed when the window (handler) is destroyed, // but we still want to remove us from the state vars callback list. wxLuaStateVariables *m_luaStateVars; wxEvtHandler *m_pHandler; wxWindowID m_id; wxEventType m_eventType; private: DECLARE_CLASS(wxLuaCallback); }; // ---------------------------------------------------------------------------- // LuaDestroyCallback - proxy class to handle the destruction of wxWindow // derived objects // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaDestroyCallback : public wxEvtHandler { public: wxLuaDestroyCallback( lua_State *state, wxWindowID id, wxEvtHandler *pHandler, int iTag); virtual ~wxLuaDestroyCallback(); void ClearState() { m_luaState = NULL; } void ClearStateVars() { m_luaStateVars = NULL; } lua_State* GetLuaState() const { return m_luaState; } wxEvtHandler* GetEvtHandler() const { return m_pHandler; } // central event handler void EventHandler(wxWindowDestroyEvent& event); protected: void OnDestroy(); // Lua state instance lua_State *m_luaState; // store the state variables see wxLuaCallback for reasoning wxLuaStateVariables *m_luaStateVars; wxEvtHandler *m_pHandler; int m_id; private: DECLARE_CLASS(wxLuaDestroyCallback) }; #endif //_WXLCALLB_H_ --- NEW FILE: wxlintrp.h --- ///////////////////////////////////////////////////////////////////////////// // Name: wxLuaInterpreter // Purpose: A simple class for a C++ wxWidgets program to embed wxLua // Author: John Labenski // Modified by: // Created: 11/05/2002 // Copyright: (c) John Labenski // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_LUA_INTERPRETER_H_ #define _WX_LUA_INTERPRETER_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxlintrp.h" #endif #include "wxlua/include/wxldefs.h" extern "C" { #include "lua/include/lua.h" // for DebugHook defines // To not include "lua.h" use these //typedef struct lua_State lua_State; //typedef struct lua_Debug lua_Debug; //typedef int (*lua_CFunction)(lua_State *); } class WXDLLEXPORT wxEvtHandler; class WXDLLIMPEXP_WXLUA wxLuaEvent; class WXDLLIMPEXP_WXLUA wxLuaStateVariables; class WXDLLIMPEXP_WXLUA wxLuaInterpreter; #include "wx/hashmap.h" WX_DECLARE_VOIDPTR_HASH_MAP( wxLuaInterpreter *, wxHashMapLuaInterpreter ); extern wxHashMapLuaInterpreter s_wxHashMapLuaInterpreter; //----------------------------------------------------------------------------- // Extra wxLua helpers that use the lua_State to find owner wxLuaInterpreter //----------------------------------------------------------------------------- extern wxLuaInterpreter *wxFindLuaInterpreter(lua_State *L); extern wxLuaStateVariables *wxFindLuaStateVariables(lua_State *L); //----------------------------------------------------------------------------- // wxLuaInterpreter // // notes : create instance, call RunString("some lua code") // Events are sent to the evthander if !null with the given id # //----------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaInterpreter : public wxObject { public: // default constructor - must call Create in order to use wxLuaInterpreter(); // Create a wxLua instance, handler and id can be null/wxID_ANY for don't care wxLuaInterpreter(wxEvtHandler *handler, wxWindowID id = wxID_ANY); wxLuaInterpreter(lua_State *L, wxEvtHandler *handler, wxWindowID id = wxID_ANY); virtual ~wxLuaInterpreter(); // (re)Create a new wxLua instance, handler and id can be null/wxID_ANY for don't care // don't forget to ShutDown the last one first (if you want to) bool Create(lua_State *L, wxEvtHandler *handler=NULL, wxWindowID id = wxID_ANY); bool Create(wxEvtHandler *handler=NULL, wxWindowID id = wxID_ANY) { return Create(NULL, handler, id); } // destroy and cleanup the interpreter, returns sucess // if 'force' then make sure all wxWindows are destroyed. bool Destroy(bool force = true); // cleanup window list void GarbageCollectWindows(bool closeWindows = false); // has the interpreter been sucessfully created bool Ok() const; // Set the event handler that the events will be sent to, can be null void SetEventHandler(wxEvtHandler *evtHandler); wxEvtHandler *GetEventHandler() const { return m_evtHandler; } // Get/Set the id that the events will be sent with void SetId(int id) { m_id = id; } int GetId() const { return m_id; } // 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 { return m_is_running; } // Break a currently running lua program void Break(const wxString &message = wxT("Interpreter stopped")); // has Break() been called bool GetBreak() const { return m_user_break; } wxString GetBreakMessage() const { return m_break_msg; } // Have lua run an internal hook function with this mask // hook = LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE | LUA_MASKCOUNT // Every count hook mask a wxEVT_LUA_DEBUG_HOOK event is sent if send_debug_evt // if yield > 0 then wxYield is called every yield milliseconds // I don't know what resonable values are // turn the hook off with count < 1 void SetLuaDebugHook(int count = 1000, int yield = 50, bool send_debug_evt = FALSE, int hook = LUA_MASKCOUNT); int GetLuaDebugHookCount() const { return m_lua_debug_hook_count; } int GetLuaDebugHookYield() const { return m_lua_debug_hook_yield; } bool GetLuaDebugHookSendEvt() const { return m_lua_debug_hook_send_evt; } int GetLuaDebugHook() const { return m_lua_debug_hook; } // registers a new function for Lua void RegisterFunction(lua_CFunction func, const wxString &funcName); // Get a pointer to the lua_State that "is" lua lua_State *GetLuaState() const; // Get a pointer to additional wxLua variables used for this lua_State wxLuaStateVariables *GetStateVariables() const; // ----------------------------------------------------------------------- // implementation // 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); // internally used so debug hook events are sent no more often than yield time unsigned long GetLastLuaDebugHookTime() const; void SetLastLuaDebugHookTime(unsigned long t); void SendEvent( wxLuaEvent &event ) const; // operators operator lua_State*() { return GetLuaState(); } protected: bool m_is_running; unsigned long m_last_debug_hook_time; bool m_user_break; wxString m_break_msg; wxLuaStateVariables *m_luaStateVariables; lua_State *m_lua_State; bool m_luaAllocated; int m_lua_debug_hook_count; int m_lua_debug_hook_yield; bool m_lua_debug_hook_send_evt; int m_lua_debug_hook; wxEvtHandler *m_evtHandler; int m_id; private : void Init(); DECLARE_ABSTRACT_CLASS(wxLuaInterpreter) }; //----------------------------------------------------------------------------- // wxLuaEvent //----------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaEvent: public wxNotifyEvent { public: wxLuaEvent(wxEventType commandType = wxEVT_NULL, wxWindowID id = wxID_ANY, wxLuaInterpreter *intrepreter=NULL); wxLuaEvent( const wxLuaEvent &event ) : wxNotifyEvent(event) { m_stop_interpreter = event.m_stop_interpreter; m_luaInterpreter = event.m_luaInterpreter; m_lua_Debug = event.m_lua_Debug; } virtual wxEvent *Clone() const { return new wxLuaEvent(*this); } // use GetString method to retrieve info // Get the line number in the code, -1 if unknown int GetLineNum() const { return m_commandInt; } wxLuaInterpreter *GetLuaInterpreter() const { return m_luaInterpreter; } void SetLuaInterpreter(wxLuaInterpreter *interp) { m_luaInterpreter = interp; } lua_State *GetLuaState() const { return m_luaInterpreter ? m_luaInterpreter->GetLuaState() : NULL; } // non null only for EVT_LUA_DEBUG_HOOK lua_Debug *GetLuaDebug() const { return m_lua_Debug; } // If called from a wxEVT_LUA_DEBUG_HOOK the interpreter will stop void StopInterpreter(bool stop) { m_stop_interpreter = stop; } bool m_stop_interpreter; wxLuaInterpreter *m_luaInterpreter; lua_Debug *m_lua_Debug; }; BEGIN_DECLARE_EVENT_TYPES() DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_CREATION, 0) // a wxLuaInterpreter is being created DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_CONSOLE, 0) // print statements and such, check GetString() DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_WARNING, 0) // unused, lua doesn't seem to warn for anything DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_ERROR, 0) // error occurred, check GetString() DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_DEBUG_HOOK, 0) // see LuaDebugHook function DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_SHUTDOWN, 0) // unused, I used this in some other interpreter, not sure why it'd be useful DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_INIT, 0) // after app starts, first idle DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WXLUA, wxEVT_LUA_DEBUGGERATTACHED, 0) // after app starts, first idle END_DECLARE_EVENT_TYPES() typedef void (wxEvtHandler::*wxLuaEventFunction)(wxLuaEvent&); #define EVT_LUA_CREATION(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_CREATION, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_CONSOLE(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_CONSOLE, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_WARNING(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_WARNING, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_ERROR(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_ERROR, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_DEBUG_HOOK(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_DEBUG_HOOK, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_SHUTDOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_SHUTDOWN, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_INIT(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_INIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUA_DEBUGGERATTACHED(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUA_DEBUGGERATTACHED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #endif // _WX_LUA_INTERPRETER_H_ --- NEW FILE: wxlbind.h --- ///////////////////////////////////////////////////////////////////////////// // Purpose: wxLuaBinding // Author: Ray Gilbert, John Labenski, J Winwood // Created: 14/11/2001 // Copyright: // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WXLBIND_H_ #define _WXLBIND_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxlbind.h" #endif #include "wxlua/include/wxldefs.h" #include "wxlua/include/wxlua.h" #include "wxlua/include/wxlintrp.h" extern "C" { #include "lua/include/lualib.h" #include "lua/include/lauxlib.h" } // ---------------------------------------------------------------------------- // wxLua binding enums and structs // ---------------------------------------------------------------------------- enum LuaType // The type of a Lua method { LuaDelete = 1, // gc routine LuaConstructor = 2, // constructor LuaDestructor = 4, // destructor (not used) LuaMethod = 8, // class method LuaGlobal = 16, // global method (not really related to the class) LuaGetProp = 32, LuaSetProp = 64 }; struct WXLUAMETHOD // defines a LUA method or property { LuaType type; // type (one of the above enumeration values) const char *name; // name of the method or property lua_CFunction func; // function that implements the method or property int params; // number of params to the method (required + optional) int required; // number of required params }; struct WXLUACLASS // defines a LUA class interface { const char *name; // name of the class WXLUAMETHOD *methods; // pointer to methods for this class int num_methods; // number of methods int baseclass_tag; // index in the class list to the base class wxClassInfo *pClassInfo; // pointer to the wxClassInfo associated with this class int *class_tag; // tag for user data allocated by ourselves // and therefore needs gc. const char *baseclass; // name of base class }; struct WXLUADEFINE // defines a wxWidgets define for wxLua { const char *name; // name bool isString; // true if a string definition FIXME use WXLUASTRING double value; // numeric value const wxChar *strValue; // string value }; struct WXLUASTRING // defines a wxWidgets define for wxLua { const char *name; // name const wxChar *value; // string value }; struct WXLUAEVENT // defines a wxWidgets Event for wxLua { const int *eventType; // new wxWidgets event type const char *eventName; // name of the event int *eventClassTag; // lua class tag }; struct WXLUAOBJECT // Defines a wxWidgets object or pointer for wxLua { const void *objPtr; // a pointer to the object or pointer const void **pObjPtr; // a pointer to the object or pointer const char *objName; // the name of the object or pointer int *objClassTag; // the class tag of the object or pointer. }; typedef WXLUACLASS* (*GetClassListFunction)(size_t &); typedef WXLUADEFINE* (*GetDefineListFunction)(size_t &); //typedef WXLUASTRING* (*GetDefineListFunction)(size_t &); FIXME - use this typedef WXLUAEVENT* (*GetEventListFunction)(size_t &); typedef WXLUAOBJECT* (*GetObjectListFunction)(size_t &); typedef WXLUAMETHOD* (*GetBuiltinListFunction)(size_t &); // ---------------------------------------------------------------------------- // wxLuaBinding // // The wxLuaBinding object binds classes, functions, objects, and // event callbacks to the lua interpreter. // ---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaBinding : public wxObject { public: wxLuaBinding(); // lua namespace e.g. "wx" wxString nameSpace; // Pointers to external Binding Functions GetClassListFunction pfGetClassList; GetDefineListFunction pfGetDefineList; GetEventListFunction pfGetEventList; GetObjectListFunction pfGetObjectList; GetBuiltinListFunction pfGetBuiltinList; // Binds C Functions/Defines/Object/Events to Lua Table void RegisterBinding(lua_State *L, bool registerTypes); // Unbinds C Functions/Defines/Object/Events by clearing Lua Table void UnRegisterBinding(lua_State *L); // size_t GetLuaClassCount() const { return m_classCount; } WXLUACLASS* GetLuaClassList() { return m_classList; } size_t GetLuaDefineCount() const { return m_defineCount; } WXLUADEFINE* GetLuaDefineList() { return m_defineList; } size_t GetLuaEventCount() { return m_eventCount; } WXLUAEVENT* GetLuaEventList() { return m_eventList; } size_t GetLuaObjectCount() { return m_objectCount; } WXLUAOBJECT* GetLuaObjectList() { return m_objectList; } size_t GetLuaBuiltinCount() { return m_builtinCount; } WXLUAMETHOD* GetLuaBuiltinList() { return m_builtinList; } bool IsTag(int tag) { return (tag >= m_startTag && tag <= m_lastTag); } // Look for base class in binding, set baseclass_tag bool SetBaseClassTag(WXLUACLASS *pClass); protected: // Registers binding, returns lua table reference to binding int LUACALL RegisterFunctions(lua_State *L, bool registerTypes); // Register the classes, definitions, objects and pointers generated by the binding // Sort the event list into order for faster event handler processing. void LUACALL RegisterGeneratedClasses(lua_State *L, int tableOffset, bool registerTypes); virtual void OnRegister(lua_State * WXUNUSED(L), bool WXUNUSED(registerTypes), int WXUNUSED(luaTable)) {} // binding objects size_t m_classCount; WXLUACLASS* m_classList; size_t m_defineCount; WXLUADEFINE* m_defineList; size_t m_eventCount; WXLUAEVENT* m_eventList; size_t m_objectCount; WXLUAOBJECT* m_objectList; size_t m_builtinCount; WXLUAMETHOD* m_builtinList; bool m_typesRegistered; // Is the binding registered int m_startTag; // The first wxLua allocated lua tag int m_lastTag; // The last wxLua lua tag of registered classes int m_wxLuaTable; // The lua tag for the wxLua private tables DECLARE_CLASS(wxLuaBinding) }; // list of wxLua Bindings WX_DECLARE_USER_EXPORTED_LIST(wxLuaBinding, wxLuaBindingList, WXDLLIMPEXP_WXLUA); #endif // _WXLBIND_H_ |