1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wxlbind.h
3 // Purpose:     wxLuaBinding
4 // Author:      Ray Gilbert, John Labenski, J Winwood
5 // Created:     14/11/2001
6 // Copyright:   (c) 2012 John Labenski, Ray Gilbert
7 // Licence:     wxWidgets licence
8 /////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef _WXLBIND_H_
11 #define _WXLBIND_H_
12 
13 #include "wxlua/wxldefs.h"
14 
15 #include <wx/event.h>
16 
17 #ifdef GetObject
18     #undef GetObject // MSVC defines this
19 #endif
20 
21 class  WXDLLIMPEXP_FWD_WXLUA wxLuaBinding;
22 class  WXDLLIMPEXP_FWD_WXLUA wxLuaState;
23 struct WXDLLIMPEXP_FWD_WXLUA wxLuaBindClass;
24 
25 // ----------------------------------------------------------------------------
26 // wxLua binding defines, enums, and structs
27 // ----------------------------------------------------------------------------
28 
29 // The inbuilt wxLua types (WXLUA_TXXX) corresponding to Lua types (LUA_TXXX)
30 //   are shifted to be positive values.
31 // The Binding wxLua types are positive integers generated automatically when
32 //   wxLua is initialized and start at WXLUA_T_MAX+1.
33 // *Use the function bool wxlua_iswxuserdatatype(wxl_type) if you want to
34 //   differentiate between the two.
35 //
36 // Note that WXLUA_TUNKNOWN is used as an initialiser for class types
37 //   and is used as an end marker for the wxLuaArgType array that
38 //   represents function prototype argument types in the wxLuaBindCFunc struct
39 //   and it must always be 0. The Lua type LUA_TNONE starts at 1 since
40 //   Lua arrays start at 1.
41 
42 // wxLua types for Lua types
43 #define WXLUA_TUNKNOWN         0  // unset and invalid, not a LUA_TXXX
44 #define WXLUA_TNONE            1  // LUA_TNONE -1
45 #define WXLUA_TNIL             2  // LUA_TNIL 0
46 #define WXLUA_TBOOLEAN         3  // LUA_TBOOLEAN 1
47 #define WXLUA_TLIGHTUSERDATA   4  // LUA_TLIGHTUSERDATA 2
48 #define WXLUA_TNUMBER          5  // LUA_TNUMBER 3
49 #define WXLUA_TSTRING          6  // LUA_TSTRING 4
50 #define WXLUA_TTABLE           7  // LUA_TTABLE 5
51 #define WXLUA_TFUNCTION        8  // LUA_TFUNCTION 6
52 #define WXLUA_TUSERDATA        9  // LUA_TUSERDATA 7
53 #define WXLUA_TTHREAD          10 // LUA_TTHREAD 8
54 #define WXLUA_TINTEGER         11 // LUA_TNUMBER but integer only, not a LUA_TXXX
55 #define WXLUA_TCFUNCTION       12 // LUA_TFUNCTION & lua_iscfunction(), not a LUA_TXXX
56 #define WXLUA_TPOINTER         13 // LUA_TLIGHTUSERDATA || LUA_TUSERDATA ||
57                                   // LUA_TFUNCTION || LUA_TTABLE || LUA_TTHREAD
58                                   // any valid type for lua_topointer(), not a LUA_TXXX
59 #define WXLUA_TANY             14 // Any data type is valid, not a LUA_TXXX
60 
61 #define WXLUA_T_MAX            14 // Max of the Lua WXLUA_TXXX values
62 #define WXLUA_T_MIN            0  // Min of the Lua WXLUA_TXXX values
63 
64 #define WXLUATYPE_NULL         15 // C++ NULL, is full wxLua type with metatable
65 
66 // Check that the Lua LUA_TXXX types are what they used to be
67 #if (LUA_TNONE     != -1) || (LUA_TNIL           != 0) || \
68     (LUA_TBOOLEAN  != 1)  || (LUA_TLIGHTUSERDATA != 2) || \
69     (LUA_TNUMBER   != 3)  || (LUA_TSTRING        != 4) || \
70     (LUA_TTABLE    != 5)  || (LUA_TFUNCTION      != 6) || \
71     (LUA_TUSERDATA != 7)  || (LUA_TTHREAD        != 8)
72 #   error "Lua has changed its LUA_TXXX defines."
73 #endif
74 
75 // Is this wxLua type one of the basic Lua types
76 #define WXLUAT_IS_LUAT(wxl_type) (((wxl_type) >= WXLUA_T_MIN) && ((wxl_type) <= WXLUA_T_MAX))
77 
78 // Blindly convert the lua_type to the wxlua_type. Note: WXLUA_TXXX = LUA_TXXX + 2
79 // *** See wxlua_luatowxluatype() for a better function ***
80 #define LUAT_TO_WXLUAT(luatype) ((luatype) + 2)
81 
82 // Returns true if the wxLua type is for a wxLua binding type and not a
83 //   generic WXLUA_TXXX type. This means that there might be a metatable for
84 //   this type in the wxlua_lreg_types_key of the LUA_REGISTRYINDEX table.
85 #define wxlua_iswxuserdatatype(wxl_type) ((wxl_type) > WXLUA_T_MAX)
86 
87 // Variables used in the wxLuaArgType member of the wxLuaBindCFunc for
88 // Lua types. The binding generator uses these and generates new ones for
89 // classes and structs as specified in the bindings.
90 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TUNKNOWN;
91 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNONE;
92 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNIL;
93 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TBOOLEAN;
94 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TLIGHTUSERDATA;
95 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNUMBER;
96 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TSTRING;
97 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TTABLE;
98 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TFUNCTION;
99 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TUSERDATA;
100 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TTHREAD;
101 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TINTEGER;
102 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TCFUNCTION;
103 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TPOINTER;
104 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TANY;
105 
106 // The NULL wxLua type is not part of the bindings, but is installed
107 // by the wxLuaState since it may be used by various bindings and does not
108 // rely on wxWidgets.
109 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_NULL;                 // wxLua type for NULL pointer
110 extern WXDLLIMPEXP_DATA_WXLUA(wxLuaBindClass) wxLuaBindClass_NULL; // for NULL pointer
111 
112 // Copies of wxLua types that are used very often, point to wxluatype_TUNKNOWN if unset.
113 // Note that we do not use the original since we may not be linked
114 // to the binding library that defines them.
115 // Their values are set at compile time if linked to library,
116 //   see wxbase_rules.lua and wxcore_rules.lua
117 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxEvent;       // wxLua type for wxEvent
118 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxWindow;      // wxLua type for wxWindow
119 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxScrollEvent; // wxLua type for wxScrollEvent - see wxLuaEventCallback::OnEvent
120 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxSpinEvent;   // wxLua type for wxSpinEvent   - see wxLuaEventCallback::OnEvent
121 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxString;      // wxLua type for wxString
122 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxArrayString; // wxLua type for wxArrayString
123 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxSortedArrayString; // wxLua type for wxSortedArrayString
124 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxArrayInt;    // wxLua type for wxArrayInt
125 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxArrayDouble; // wxLua type for wxArrayDouble
126 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxMemoryBuffer; // wxLua type for wxMemoryBuffer
127 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxPoint;       // wxLua type for wxPoint
128 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxPoint2DDouble;       // wxLua type for wxPoint2DDouble
129 
130 // ----------------------------------------------------------------------------
131 // wxLuaArgType a pointer to a declared wxLua type, see wxLuaBindCFunc::argtypes
132 // ----------------------------------------------------------------------------
133 
134 typedef int* wxLuaArgType;      // address of wxLua class type (a pointer to it)
135 extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgType) g_wxluaargtypeArray_None[1]; // = {0}
136 
137 // ----------------------------------------------------------------------------
138 // wxLuaMethod_Type: Values for the wxLuaBindMethod::method_type and wxLuaBindCFunc::method_type
139 // ----------------------------------------------------------------------------
140 enum wxLuaMethod_Type
141 {
142     WXLUAMETHOD_CONSTRUCTOR = 0x0001, // class constructor
143     WXLUAMETHOD_METHOD      = 0x0002, // class member function
144     WXLUAMETHOD_CFUNCTION   = 0x0004, // global C function (not part of a class)
145     WXLUAMETHOD_GETPROP     = 0x0008, // Get %property funcName, read
146     WXLUAMETHOD_SETPROP     = 0x0010, // Set %property funcName, write
147 
148     WXLUAMETHOD_STATIC      = 0x1000, // Class member function is static
149 
150     WXLUAMETHOD_DELETE      = 0x2000, // This is the delete function that wxLua has generated
151                                       // to delete this class and is not part of the
152                                       // original class.
153 
154     WXLUAMETHOD_MASK        = 0xFFFF  // Match any type for searching
155 };
156 
157 // ----------------------------------------------------------------------------
158 // wxLuaBindCFunc - Defines a single function for wxLua
159 // ----------------------------------------------------------------------------
160 
161 struct WXDLLIMPEXP_WXLUA wxLuaBindCFunc
162 {
163     lua_CFunction lua_cfunc;   // C function that implements the method or property
164     int           method_type; // enum wxLuaMethod_Type flags for this function
165     int           minargs;     // Min number of required args
166     int           maxargs;     // Max number of args allowed, equal to length of argtypes array
167     wxLuaArgType* argtypes;    // Array of wxLua types representing each argument, NULL terminated.
168 };
169 
170 // ----------------------------------------------------------------------------
171 // wxLuaBindMethod - Defines a method or property (a function) for wxLua
172 // ----------------------------------------------------------------------------
173 
174 struct WXDLLIMPEXP_WXLUA wxLuaBindMethod
175 {
176     const char*      name;          // Name of the method or property
177     int              method_type;   // enum wxLuaMethod_Type flags for this method.
178                                     //   Note that each func has own type, this is ored values of them.
179     wxLuaBindCFunc*  wxluacfuncs;   // Array of C functions for this method
180     int              wxluacfuncs_n; // Number of C functions (overloaded > 1) for this method
181     wxLuaBindMethod* basemethod;    // Overloaded method from the base class, else NULL.
182 };
183 
184 // ----------------------------------------------------------------------------
185 // wxLuaBindNumber - Defines a numeric value for wxLua
186 // ----------------------------------------------------------------------------
187 
188 struct WXDLLIMPEXP_WXLUA wxLuaBindNumber
189 {
190     const char* name;          // name
191     double      value;         // numeric value
192 };
193 
194 // ----------------------------------------------------------------------------
195 // wxLuaBindString - Defines a wxWidgets wxChar* string for wxLua
196 // ----------------------------------------------------------------------------
197 
198 struct WXDLLIMPEXP_WXLUA wxLuaBindString
199 {
200     const char*   name;          // name
201     const char*   c_string;      // string value
202     const wxChar* wxchar_string; // string value
203 };
204 
205 // ----------------------------------------------------------------------------
206 // wxLuaBindEvent - Defines a wxWidgets wxEventType for wxLua
207 // ----------------------------------------------------------------------------
208 
209 #if (wxVERSION_NUMBER >= 2900)
210     // In 2.9 wxEVT_XXX are declared as wxEventTypeTag<E.G. wxCommandEvent> wxEVT_XXX;
211     // The operator const wxEventType& is used to get the int wxEventType.
212     #define WXLUA_GET_wxEventType_ptr(wxEVT_XXX) &((const wxEventType&)(wxEVT_XXX))
213 #else
214     #define WXLUA_GET_wxEventType_ptr(wxEVT_XXX) &(wxEVT_XXX)
215 #endif
216 
217 struct WXDLLIMPEXP_WXLUA wxLuaBindEvent
218 {
219     const char*        name;      // Name of the wxEventType, e.g. "wxEVT_COMMAND_MENU_SELECTED"
220     const wxEventType* eventType; // wxWidgets event type, e.g. &wxEVT_COMMAND_MENU_SELECTED
221     int*               wxluatype; // wxLua class type that wxWidgets uses for this wxEventType,
222                                   //   e.g. &wxluatype_wxCommandEvent
223 };
224 
225 // ----------------------------------------------------------------------------
226 // wxLuaBindEvent - Defines an object or pointer for wxLua
227 // ----------------------------------------------------------------------------
228 
229 struct WXDLLIMPEXP_WXLUA wxLuaBindObject
230 {
231     const char*  name;      // Name of the object or pointer
232     int*         wxluatype; // wxLua class type of the object or pointer.
233     const void*  objPtr;    // Pointer to the object, e.g. &wxDefaultPosition
234     const void** pObjPtr;   // Pointer to the object pointer, e.g. (const void **)&wxThePenList
235                             // This is done since the object may not be created at compile time.
236 };
237 
238 // ----------------------------------------------------------------------------
239 // wxLuaBindClass - Defines a C++ class or struct for wxLua
240 // ----------------------------------------------------------------------------
241 
242 typedef void (*wxlua_delete_function) (void** o);
243 
244 struct WXDLLIMPEXP_WXLUA wxLuaBindClass
245 {
246     const char*      name;           // Name of the class or struct
247     wxLuaBindMethod* wxluamethods;   // Pointer to array of methods for this class
248     int              wxluamethods_n; // Number of methods
249     wxClassInfo*     classInfo;      // Pointer to the wxClassInfo associated with this class or NULL.
250     int*             wxluatype;      // wxLua class type for userdata
251     const char**     baseclassNames; // Names of base classes, or NULL if no base classes.
252                                      // This is a NULL terminated array of strings.
253     wxLuaBindClass** baseBindClasses;// Pointers to the base classes or NULL for no base classes.
254                                      // This member is set after all the bindings are
255                                      // registered since the base class may be from
256                                      // a different module and so it can't be set at compile time.
257                                      // This array is one shorter than the baseclassNames array
258                                      // and you should use it rather than this to check the length
259                                      // since any one of these may be NULL if the
260                                      // library or module with the base class is not loaded.
261 
262     wxLuaArgType*    baseclass_wxluatypes;     // NULL terminated array of wxLua types for the base classes
263                                                // that are from second or higher base classes
264     wxIntPtr*        baseclass_vtable_offsets; // Array of pointer offsets of the second or higher
265                                                // base classes from the root class.
266                                                // See note above wxluaT_getuserdatatype()
267 
268     wxLuaBindNumber* enums;          // Class member enums or NULL if none
269     int              enums_n;        // number of enums
270 
271     wxlua_delete_function delete_fn; // Function that will cast the void* pointer
272                                      // to the class type and then call delete on it.
273 };
274 
275 // ----------------------------------------------------------------------------
276 // C functions for the metatable for wxLua userdata installed by the wxLuaBinding
277 // ----------------------------------------------------------------------------
278 
279 // Generic delete function for userdata binding objects
280 WXDLLIMPEXP_WXLUA int LUACALL wxlua_userdata_delete(lua_State *L);
281 
282 // memory deallocation function for created wxLuaBindClass defined objects, Lua's __gc metatable index
283 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__gc(lua_State *L);
284 // Lua 'set table' function for created wxLuaBindClass defined objects, Lua's __newindex metatable index
285 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__newindex(lua_State *L);
286 // Lua 'get table' function for created wxLuaBindClass defined objects, Lua's __index metatable index
287 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__index(lua_State *L);
288 // Lua 'tostring' function for created wxLuaBindClass defined objects, Lua's __tostring metatable index
289 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__tostring(lua_State *L);
290 
291 // ----------------------------------------------------------------------------
292 // Overloaded binding function call helper functions.
293 // ----------------------------------------------------------------------------
294 
295 // Redirect a Lua function call to one wxLuaBindCFunc from a list of overloaded functions.
296 // The 1st upvalue must be a wxLuaBindMethod.
297 WXDLLIMPEXP_WXLUA int LUACALL wxlua_callOverloadedFunction(lua_State* L);
298 // Redirect a Lua function call to one wxLuaBindCFunc from a list of overloaded functions
299 // declared in the wxLuaBindMethod.
300 WXDLLIMPEXP_WXLUA int LUACALL wxlua_callOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod);
301 // Get a human readable string of the Lua args (items on the stack) for a function call
302 WXDLLIMPEXP_WXLUA wxString wxlua_getLuaArgsMsg(lua_State* L, int start_stack_idx, int end_stack_idx);
303 // Get a human readable wxString of the wxLuaArgType arrays for the functions in the method
304 WXDLLIMPEXP_WXLUA wxString wxlua_getBindMethodArgsMsg(lua_State* L, struct wxLuaBindMethod* wxlMethod);
305 
306 // ----------------------------------------------------------------------------
307 // wxLuaBinding - binds classes, functions, objects, and event callbacks to
308 //                the wxLuaState.
309 // ----------------------------------------------------------------------------
310 
311 // wxArray of wxLua Bindings
312 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxLuaBinding*, wxLuaBindingArray, class WXDLLIMPEXP_WXLUA);
313 
314 class WXDLLIMPEXP_WXLUA wxLuaBinding : public wxObject
315 {
316 public:
317     wxLuaBinding();
~wxLuaBinding()318     virtual ~wxLuaBinding() {}
319 
320     // Register all the bindings added to the static member wxLuaBindingArray.
321     // Leaves nothing on the stack.
322     static bool RegisterBindings(const wxLuaState& wxlState);
323 
324     // Binds C Functions/Defines/Object/Events to a Lua table with binding's namespace.
325     // The Lua table that the bindings were installed into is left on the top
326     //   of the stack and you must pop it when done.
327     virtual bool RegisterBinding(const wxLuaState& wxlState);
328 
329     // Create the metatable for the class and install it into the Lua registry.
330     static bool InstallClassMetatable(lua_State* L, const wxLuaBindClass* wxlClass);
331     // Install a single wxLuaBindClass struct into the table at the top
332     // of the stack.
333     static bool InstallClass(lua_State* L, const wxLuaBindClass* wxlClass);
334 
335     // -----------------------------------------------------------------------
336 
337     // Get/Set the binding name, a unique name of the binding.
338     //   By default it is the "hook_cpp_namespace" used in the binding
339     //   generator which needs to be a unique name.
GetBindingName()340     wxString GetBindingName() const           { return m_bindingName; }
SetBindingName(const wxString & name)341     void SetBindingName(const wxString& name) { m_bindingName = name; }
342 
343     // Get/Set the namespace table in Lua that this binding will be installed to
GetLuaNamespace()344     wxString GetLuaNamespace() const                { return m_nameSpace; }
SetLuaNamespace(const wxString & nameSpace)345     void SetLuaNamespace(const wxString& nameSpace) { m_nameSpace = nameSpace; }
346 
GetClassCount()347     size_t GetClassCount() const        { return m_classCount; }
GetClassArray()348     wxLuaBindClass* GetClassArray()     { return m_classArray; }
349 
GetNumberCount()350     size_t GetNumberCount() const       { return m_numberCount; }
GetNumberArray()351     wxLuaBindNumber* GetNumberArray()   { return m_numberArray; }
352 
GetStringCount()353     size_t GetStringCount() const       { return m_stringCount; }
GetStringArray()354     wxLuaBindString* GetStringArray()   { return m_stringArray; }
355 
GetEventCount()356     size_t GetEventCount() const        { return m_eventCount; }
GetEventArray()357     wxLuaBindEvent* GetEventArray()     { return m_eventArray; }
358 
GetObjectCount()359     size_t GetObjectCount() const       { return m_objectCount; }
GetObjectArray()360     wxLuaBindObject* GetObjectArray()   { return m_objectArray; }
361 
GetFunctionCount()362     size_t GetFunctionCount() const     { return m_functionCount; }
GetFunctionArray()363     wxLuaBindMethod* GetFunctionArray() { return m_functionArray; }
364 
365     // Is this wxLua type defined in this binding?
HaswxLuaType(int wxl_type)366     bool HaswxLuaType(int wxl_type) const { return (wxl_type >= m_first_wxluatype) && (wxl_type <= m_last_wxluatype); }
367 
368     // -----------------------------------------------------------------------
369     // These functions only look through the binding data of this wxLuaBinding
370 
371     // Find the wxLuaBindEvent with the wxEventType, returns NULL if not found.
372     const wxLuaBindEvent* GetBindEvent(wxEventType eventType) const;
373     // Look up the wxEventType name as a string, from the wxEventType number
374     //  in the wxLuaBindEvent* struct list of this binding.
375     wxString GetEventTypeName(wxEventType eventType) const;
376     // Get the wxLuaBindClass that has this wxLua type, or NULL if none
377     const wxLuaBindClass* GetBindClass(int wxl_type) const;
378     // Get the wxLuaBindClass that has this name, or NULL if none
379     const wxLuaBindClass* GetBindClass(const char* className) const;
380     // Get the first wxLuaBindClass that has this wxLuaBindMethod
381     const wxLuaBindClass* GetBindClass(const wxLuaBindMethod* wxlMethod) const;
382     // Get the first wxLuaBindClass that has this wxLuaBindCFunc
383     const wxLuaBindClass* GetBindClass(const wxLuaBindCFunc* wxlCFunc) const;
384 
385     // -----------------------------------------------------------------------
386     // These functions search through the static wxLuaBinding::GetBindingArray()
387     // for the items.
388 
389     // Get the installed wxLuaBinding with the given
390     //   wxLuaBinding::GetBindingName() or NULL for no match.
391     static wxLuaBinding* GetLuaBinding(const wxString& bindingName);
392 
393     // Get wxLuaBindClass for given wxLua type using wxLuaBindClass::wxluatype,
394     //   returns NULL on failure.
395     static const wxLuaBindClass* FindBindClass(int wxl_type);
396     // Get wxLuaBindClass that has this class name using wxLuaBindClass::name,
397     //   returns NULL on failure.
398     static const wxLuaBindClass* FindBindClass(const char* className);
399     // Get the first wxLuaBindClass that has this particular wxLuaBindMethod
400     //   returns NULL on failure.
401     static const wxLuaBindClass* FindBindClass(const wxLuaBindMethod* wxlMethod);
402     // Get the first wxLuaBindClass that has this particular wxLuaBindCFunc in its methods
403     //   returns NULL on failure.
404     static const wxLuaBindClass* FindBindClass(const wxLuaBindCFunc* wxlCFunc);
405 
406     // Get wxLuaBindEvent for given wxEventType (wxEvent::GetEventType()) by finding
407     //   the matching wxLuaBindEvent::eventType.
408     //   returns NULL on failure.
409     static const wxLuaBindEvent* FindBindEvent(wxEventType eventType);
410 
411     // Get the wxLuaBinding that has this wxLuaBindMethod in its wxLuaBinding::GetFunctionArray().
412     //   returns NULL on failure.
413     static wxLuaBinding* FindMethodBinding(const wxLuaBindMethod* wxlMethod);
414 
415     // -----------------------------------------------------------------------
416     // These functions search through the input struct
417 
418     // Lookup a wxLuaBindMethod function or property called methodName in the wxLuaBindClass
419     // that is also of the wxLuaMethod_Type method_type. The method_type may be
420     // ored values and the first match found is returned or NULL if not found.
421     // If the wxLuaBindMethod cannot be found on the current class recurse through base classes
422     //   if search_baseclasses.
423     static wxLuaBindMethod* GetClassMethod(const wxLuaBindClass *wxlClass, const char *methodName,
424                                            int method_type, bool search_baseclasses);
425 
426     // -----------------------------------------------------------------------
427 
428     // Get all the bindings that were initialized using the generated binding
429     //   function wxLuaBinding_[binding name]_init().
430     //   You can adjust the array *only* if you do not have any wxLuaStates
431     //   created, otherwise the wxLua types will be out of sync.
GetBindingArray()432     static wxLuaBindingArray& GetBindingArray() { return sm_bindingArray; }
433 
434     // -----------------------------------------------------------------------
435 
436     // Initialize all of the bindings by iterating the GetBindingArray() and
437     // setting the base classes and base class functions. This function
438     // is automatically run by the wxLuaState and should not need to be called
439     // unless you later add a new binding to the array, in which case force it to be rerun.
440     static void InitAllBindings(bool force_update = false);
441 
442 protected:
443 
444     // Call only once after subclassed version is created to sort the bindings appropriately
445     void InitBinding();
446 
447     // Register the classes, defines, strings, events, objects, and functions
448     // stored in the binding arrays. The Lua table to install them into
449     // must be at the top of the stack.
450     virtual void DoRegisterBinding(const wxLuaState& wxlState) const;
451 
452     // binding objects
453     size_t           m_classCount;
454     wxLuaBindClass*  m_classArray;
455     size_t           m_numberCount;
456     wxLuaBindNumber* m_numberArray;
457     size_t           m_stringCount;
458     wxLuaBindString* m_stringArray;
459     size_t           m_eventCount;
460     wxLuaBindEvent*  m_eventArray;
461     size_t           m_objectCount;
462     wxLuaBindObject* m_objectArray;
463     size_t           m_functionCount;
464     wxLuaBindMethod* m_functionArray;
465 
466     wxString m_bindingName;     // A unique name of the binding
467     wxString m_nameSpace;       // Lua table namespace e.g. "wx"
468     int m_first_wxluatype;      // The first wxLua type allocated for a class
469     int m_last_wxluatype;       // The last wxLua type of registered classes
470 
471     static wxLuaBindingArray sm_bindingArray;
472     static int               sm_bindingArray_initialized;
473     static int               sm_wxluatype_max;
474 
475     DECLARE_ABSTRACT_CLASS(wxLuaBinding)
476 };
477 
478 #endif // _WXLBIND_H_
479