wxlbind.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // Name:        wxlbind.h
00003 // Purpose:     wxLuaBinding
00004 // Author:      Ray Gilbert, John Labenski, J Winwood
00005 // Created:     14/11/2001
00006 // Copyright:   Ray Gilbert
00007 // Licence:     wxWidgets licence
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 #ifndef _WXLBIND_H_
00011 #define _WXLBIND_H_
00012 
00013 #include "wxlua/include/wxldefs.h"
00014 
00015 #ifdef GetObject
00016     #undef GetObject // MSVC defines this
00017 #endif
00018 
00019 class WXDLLIMPEXP_WXLUA wxLuaBinding;
00020 class WXDLLIMPEXP_WXLUA wxLuaState;
00021 struct WXDLLIMPEXP_WXLUA wxLuaBindClass;
00022 
00023 // ----------------------------------------------------------------------------
00024 // wxLua binding defines, enums, and structs
00025 // ----------------------------------------------------------------------------
00026 
00027 // The inbuilt wxLua types (WXLUA_TXXX) corresponding to Lua types (LUA_TXXX)
00028 //   are shifted to be positive values.
00029 // The Binding wxLua types are positive integers generated automatically when
00030 //   wxLua is initialized and start at WXLUA_T_MAX+1.
00031 // *Use the function bool wxlua_iswxuserdatatype(wxl_type) if you want to
00032 //   differentiate between the two.
00033 //
00034 // Note that WXLUA_TUNKNOWN is used as an initialiser for class types
00035 //   and is used as an end marker for the wxLuaArgType array that
00036 //   represents function prototype argument types in the wxLuaBindCFunc struct
00037 //   and it must always be 0.
00038 
00039 // wxLua types for Lua types
00040 #define WXLUA_TUNKNOWN         0  // unset and invalid, not a LUA_TXXX
00041 #define WXLUA_TNONE            1  // LUA_TNONE -1
00042 #define WXLUA_TNIL             2  // LUA_TNIL 0
00043 #define WXLUA_TBOOLEAN         3  // LUA_TBOOLEAN 1
00044 #define WXLUA_TLIGHTUSERDATA   4  // LUA_TLIGHTUSERDATA 2
00045 #define WXLUA_TNUMBER          5  // LUA_TNUMBER 3
00046 #define WXLUA_TSTRING          6  // LUA_TSTRING 4
00047 #define WXLUA_TTABLE           7  // LUA_TTABLE 5
00048 #define WXLUA_TFUNCTION        8  // LUA_TFUNCTION 6
00049 #define WXLUA_TUSERDATA        9  // LUA_TUSERDATA 7
00050 #define WXLUA_TTHREAD          10 // LUA_TTHREAD 8
00051 #define WXLUA_TINTEGER         11 // LUA_TNUMBER but integer only, not a LUA_TXXX
00052 #define WXLUA_TCFUNCTION       12 // LUA_TFUNCTION & lua_iscfunction(), not a LUA_TXXX
00053 
00054 #define WXLUA_T_MAX            12 // Max of the Lua WXLUA_TXXX values
00055 #define WXLUA_T_MIN            0  // Min of the Lua WXLUA_TXXX values
00056 
00057 #define WXLUATYPE_NULL         13 // C++ NULL, is full wxLua type with metatable
00058 
00059 // Check that the Lua LUA_TXXX types are what they used to be
00060 #if (LUA_TNONE != -1) || (LUA_TNIL != 0) || (LUA_TBOOLEAN != 1) || (LUA_TLIGHTUSERDATA != 2) || \
00061     (LUA_TNUMBER != 3) || (LUA_TSTRING != 4) || (LUA_TTABLE != 5) || (LUA_TFUNCTION != 6) || \
00062     (LUA_TUSERDATA != 7) || (LUA_TTHREAD != 8)
00063 #   error "Lua has changed it's LUA_TXXX defines."
00064 #endif
00065 
00066 // Is this wxLua type one of the basic Lua types
00067 #define WXLUAT_IS_LUAT(wxl_type) (((wxl_type) >= WXLUA_T_MIN) && ((wxl_type) <= WXLUA_T_MAX))
00068 
00069 // Blindly convert the lua_type to the wxlua_type. Note: WXLUA_TXXX = LUA_TXXX + 2
00070 // *** See wxlua_luatowxluatype() for a better function ***
00071 #define LUAT_TO_WXLUAT(luatype) ((luatype) + 2)
00072 
00073 // Returns true if the wxLua type is for a wxLua binding type and not a
00074 //   generic WXLUA_TXXX type. This means that there might be a metatable for
00075 //   this type in the wxlua_lreg_types_key of the LUA_REGISTRYINDEX table.
00076 #define wxlua_iswxuserdatatype(wxl_type) ((wxl_type) > WXLUA_T_MAX)
00077 
00078 // Variables used in the wxLuaArgType member of the wxLuaBindCFunc for
00079 // Lua types. The binding generator uses these and generates new ones for
00080 // classes and structs as specified in the bindings.
00081 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNONE;
00082 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNIL;
00083 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TBOOLEAN;
00084 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TLIGHTUSERDATA;
00085 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TNUMBER;
00086 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TSTRING;
00087 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TTABLE;
00088 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TFUNCTION;
00089 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TUSERDATA;
00090 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TTHREAD;
00091 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TINTEGER;
00092 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_TCFUNCTION;
00093 
00094 // The NULL wxLua type is not part of the bindings, but is installed
00095 // by the wxLuaState since it may be used by various bindings and does not
00096 // rely on wxWidgets.
00097 extern WXDLLIMPEXP_DATA_WXLUA(int) wxluatype_NULL;                 // wxLua type for NULL pointer
00098 extern WXDLLIMPEXP_DATA_WXLUA(wxLuaBindClass) wxLuaBindClass_NULL; // for NULL pointer
00099 
00100 // Copies of wxLua types that are used very often.
00101 // Note that we do not use the original since we may not be linked
00102 // to the binding library that defines them.
00103 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxEvent;       // wxLua type for wxEvents
00104 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxWindow;      // wxLua type for wxWindows
00105 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxString;      // wxLua type for wxStrings
00106 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxArrayString; // wxLua type for wxArrayString
00107 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxSortedArrayString; // wxLua type for wxSortedArrayString
00108 extern WXDLLIMPEXP_DATA_WXLUA(int*) p_wxluatype_wxArrayInt;    // wxLua type for wxArrayInt
00109 
00110 // ----------------------------------------------------------------------------
00111 // wxLuaArgType a pointer to a declared wxLua type, see wxLuaBindCFunc::argtypes
00112 // ----------------------------------------------------------------------------
00113 
00114 typedef int* wxLuaArgType;      // address of wxLua class type (a pointer to it)
00115 extern WXDLLIMPEXP_DATA_WXLUA(wxLuaArgType) g_wxluaargtypeArray_None[1]; // = {0}
00116 
00117 // ----------------------------------------------------------------------------
00118 // wxLuaMethod_Type: Values for the wxLuaBindMethod::method_type and wxLuaBindCFunc::method_type
00119 // ----------------------------------------------------------------------------
00120 enum wxLuaMethod_Type
00121 {
00122     WXLUAMETHOD_CONSTRUCTOR = 0x0001, // constructor
00123     WXLUAMETHOD_METHOD      = 0x0002, // class member function
00124     WXLUAMETHOD_CFUNCTION   = 0x0004, // global C function (not part of a class)
00125     WXLUAMETHOD_GETPROP     = 0x0008, // Get %property funcName, read
00126     WXLUAMETHOD_SETPROP     = 0x0010, // Set %property funcName, write
00127 
00128     WXLUAMETHOD_STATIC      = 0x1000, // Class member function is static
00129 
00130     WXLUAMETHOD_DELETE      = 0x2000, // This is the delete function that wxLua has generated
00131                                       // to delete this class and is not part of the
00132                                       // original class.
00133 
00134     WXLUAMETHOD_ENCAPSULATE = 0x4000, // This class is not derived from a wxObject
00135 
00136     WXLUAMETHOD_CHECKED_OVERLOAD = 0x10000, // Class method has been checked to see if it is
00137                                             // overloaded function from the base class by
00138                                             // wxLuaBinding::InitAllBindings().
00139                                             // wxLuaBindMethod::basemethod is !NULL
00140                                             // if an overloaded function was found.
00141 
00142     WXLUAMETHOD_SEARCH_MASK = 0xFFFF,    // Helper for wxLuaBinding::GetClassMethod(), ignore WXLUAMETHOD_CHECKED_OVERLOAD
00143     WXLUAMETHOD_SORT_MASK   = 0xFFFF,    // Helper for wxLuaBinding::InitAllBindings(), ignore WXLUAMETHOD_CHECKED_OVERLOAD
00144 };
00145 
00146 // ----------------------------------------------------------------------------
00147 // wxLuaBindCFunc - Defines a single function for wxLua
00148 // ----------------------------------------------------------------------------
00149 
00150 struct WXDLLIMPEXP_WXLUA wxLuaBindCFunc
00151 {
00152     lua_CFunction lua_cfunc;   // C function that implements the method or property
00153     int           method_type; // enum wxLuaMethod_Type flags for this function
00154     int           minargs;     // Min number of required args
00155     int           maxargs;     // Max number of args allowed
00156     wxLuaArgType* argtypes;    // Array of wxLua types representing each argument, NULL terminated.
00157 };
00158 
00159 // ----------------------------------------------------------------------------
00160 // wxLuaBindMethod - Defines a method or property (a function) for wxLua
00161 // ----------------------------------------------------------------------------
00162 
00163 struct WXDLLIMPEXP_WXLUA wxLuaBindMethod
00164 {
00165     const char*      name;          // Name of the method or property
00166     int              method_type;   // enum wxLuaMethod_Type flags for this method.
00167                                     //   Note that each func has own type, this is ored values of them.
00168     wxLuaBindCFunc*  wxluacfuncs;   // Array of C functions for this method
00169     int              wxluacfuncs_n; // Number of C functions (overloaded > 1) for this method
00170     wxLuaBindMethod* basemethod;    // Overloaded method from the base class, else NULL.
00171                                     //   See comments for WXLUAMETHOD_CHECKED_OVERLOAD
00172 };
00173 
00174 // ----------------------------------------------------------------------------
00175 // wxLuaBindNumber - Defines a numeric value for wxLua
00176 // ----------------------------------------------------------------------------
00177 
00178 struct WXDLLIMPEXP_WXLUA wxLuaBindNumber
00179 {
00180     const char* name;          // name
00181     double      value;         // numeric value
00182 };
00183 
00184 extern WXDLLIMPEXP_DATA_WXLUA(wxLuaBindNumber) g_wxluanumberArray_None[1]; // = {{0,0}}
00185 
00186 // ----------------------------------------------------------------------------
00187 // wxLuaBindString - Defines a wxWidgets wxChar* string for wxLua
00188 // ----------------------------------------------------------------------------
00189 
00190 struct WXDLLIMPEXP_WXLUA wxLuaBindString
00191 {
00192     const char*   name;        // name
00193     const wxChar* value;       // string value
00194 };
00195 
00196 // ----------------------------------------------------------------------------
00197 // wxLuaBindEvent - Defines a wxWidgets wxEventType for wxLua
00198 // ----------------------------------------------------------------------------
00199 
00200 struct WXDLLIMPEXP_WXLUA wxLuaBindEvent
00201 {
00202     const char*        name;      // Name of the wxEventType, e.g. "wxEVT_COMMAND_MENU_SELECTED"
00203     const wxEventType* eventType; // wxWidgets event type, e.g. &wxEVT_COMMAND_MENU_SELECTED
00204     int*               wxluatype; // wxLua class type that wxWidgets uses for this wxEventType,
00205                                   //   e.g. &wxluatype_wxCommandEvent
00206 };
00207 
00208 // ----------------------------------------------------------------------------
00209 // wxLuaBindEvent - Defines an object or pointer for wxLua
00210 // ----------------------------------------------------------------------------
00211 
00212 struct WXDLLIMPEXP_WXLUA wxLuaBindObject
00213 {
00214     const char*  name;      // Name of the object or pointer
00215     int*         wxluatype; // wxLua class type of the object or pointer.
00216     const void*  objPtr;    // Pointer to the object, e.g. &wxDefaultPosition
00217     const void** pObjPtr;   // Pointer to the object pointer, e.g. (const void **)&wxThePenList
00218 };
00219 
00220 // ----------------------------------------------------------------------------
00221 // wxLuaBindClass - Defines a C++ class or struct for wxLua
00222 // ----------------------------------------------------------------------------
00223 
00224 struct WXDLLIMPEXP_WXLUA wxLuaBindClass
00225 {
00226     const char*      name;           // Name of the class or struct
00227     wxLuaBindMethod* wxluamethods;   // Pointer to methods for this class
00228     int              wxluamethods_n; // Number of methods
00229     wxClassInfo*     classInfo;      // Pointer to the wxClassInfo associated with this class or NULL.
00230     int*             wxluatype;      // wxLua class type for userdata
00231     const char**     baseclassNames; // Names of base classes, or NULL if no base classes.
00232                                      // This is a NULL terminated array of strings.
00233     wxLuaBindClass** baseBindClasses;// Pointers to the base classes or NULL for no base classes.
00234                                      // This member is set after all the bindings are
00235                                      // registered since the base class may be from
00236                                      // a different module and so it can't be set at compile time.
00237                                      // This array is one shorter than the baseclassNames array
00238                                      // and you should use it rather than this to check the length
00239                                      // since any one of these may be NULL if the
00240                                      // library or module with the base class is not loaded.
00241 
00242     wxLuaBindNumber* enums;          // Class member enums or NULL if none
00243     int              enums_n;        // number of enums
00244 };
00245 
00246 // ----------------------------------------------------------------------------
00247 // C functions for the metatable for wxLua userdata installed by the wxLuaBinding
00248 // ----------------------------------------------------------------------------
00249 
00250 // Generic delete function for userdata binding objects
00251 WXDLLIMPEXP_WXLUA int LUACALL wxlua_userdata_delete(lua_State *L);
00252 
00253 // memory deallocation function for created wxLuaBindClass defined objects, Lua's __gc metatable index
00254 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__gc(lua_State *L);
00255 // Lua 'set table' function for created wxLuaBindClass defined objects, Lua's __newindex metatable index
00256 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__newindex(lua_State *L);
00257 // Lua 'get table' function for created wxLuaBindClass defined objects, Lua's __index metatable index
00258 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__index(lua_State *L);
00259 // Lua 'tostring' function for created wxLuaBindClass defined objects, Lua's __tostring metatable index
00260 WXDLLIMPEXP_WXLUA int LUACALL wxlua_wxLuaBindClass__tostring(lua_State *L);
00261 
00262 // ----------------------------------------------------------------------------
00263 // Overloaded binding function call helper functions.
00264 // ----------------------------------------------------------------------------
00265 
00266 // Redirect a Lua function call to 1 wxLuaBindCFunc from a list of overloaded functions.
00267 // The 1st upvalue must be a wxLuaBindMethod.
00268 int LUACALL wxlua_callOverloadedFunction(lua_State* L);
00269 // Redirect a Lua function call to 1 wxLuaBindCFunc from a list of overloaded functions
00270 // declared in the wxLuaBindMethod.
00271 WXDLLIMPEXP_WXLUA int LUACALL wxlua_callOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod);
00272 // Get a human readable string of the Lua args (items on the stack) for a function call
00273 WXDLLIMPEXP_WXLUA wxString wxlua_getLuaArgsMsg(lua_State* L, int start_stack_idx, int end_stack_idx);
00274 // Get a human readable wxString of the wxLuaArgType arrays for the functions in the method
00275 WXDLLIMPEXP_WXLUA wxString wxlua_getBindMethodArgsMsg(lua_State* L, struct wxLuaBindMethod* wxlMethod);
00276 
00277 // ----------------------------------------------------------------------------
00278 // wxLuaObject - Wraps a reference to a Lua object reference inside a
00279 //   wxObject-derived class so that a Lua object can be used for userdata.
00280 // Also with a simple extension by a proxy member value it can be used
00281 //   to provide pointers to the wxValidator classes.
00282 // ----------------------------------------------------------------------------
00283 
00284 enum wxLuaObject_Type
00285 {
00286     wxLUAOBJECT_NONE     = 0, // nothing is allocated
00287     wxLUAOBJECT_BOOL     = 1, // bool allocated
00288     wxLUAOBJECT_INT      = 2, // int allocated
00289     wxLUAOBJECT_STRING   = 4, // wxString allocated
00290     wxLUAOBJECT_ARRAYINT = 8  // wxArrayInt allocated
00291 };
00292 
00293 class WXDLLIMPEXP_WXLUA wxLuaObject : public wxObject, wxClientData
00294 {
00295 public:
00296     // Wrap the item at the lua_State's stack index and create a reference to it
00297     // in the wxlua_lreg_refs_key registy table
00298     wxLuaObject(const wxLuaState& wxlState, int stack_idx);
00299 
00300     virtual ~wxLuaObject();
00301 
00302     // Get the value of the reference object and push it onto the stack.
00303     // (or a proxy if the object has been aliased for a wxValidator class.)
00304     // returns true if the object is valid and has a reference, returns false
00305     // on failure and nothing is pushed on the stack.
00306     bool GetObject();
00307     // Remove any existing reference and allocate another.
00308     // You cannot call this after calling GetXXXPtr(), but only if this wraps a
00309     // stack item.
00310     void SetObject(int stack_idx);
00311 
00312     // The following methods are used by the wxValidator interface
00313     // Call GetObject() so that it's on the stack then try to get the value of
00314     // the object as the specified type and set the member variable equal to it
00315     // and return a pointer to member variable to a function that wants
00316     // a pointer to read/write from/to.
00317     // You may only call only one of these per instance of a wxLuaObject class.
00318     bool       *GetBoolPtr();
00319     int        *GetIntPtr();
00320     wxString   *GetStringPtr();
00321     wxArrayInt *GetArrayPtr();
00322 
00323     // Return a flag value that indicated whether the
00324     // object is being used by a wxValidator class (else wxLUAOBJECT_NONE).
00325     wxLuaObject_Type GetAllocationFlag() const { return m_alloc_flag; }
00326 
00327     wxLuaState GetwxLuaState() const;
00328 
00329 protected:
00330     wxLuaState* m_wxlState;   // a pointer due to #include recursion.
00331     int         m_reference;  // reference in wxlua_lreg_refs_key registry table
00332 
00333     wxLuaObject_Type m_alloc_flag; // type of object for wxValidator interface
00334 
00335     union                          // object stored for wxValidator interface
00336     {
00337         bool        m_bool;
00338         int         m_int;
00339         wxString*   m_string;
00340         wxArrayInt* m_arrayInt;
00341     };
00342 
00343 private:
00344     DECLARE_ABSTRACT_CLASS(wxLuaObject)
00345 };
00346 
00347 // ----------------------------------------------------------------------------
00348 // wxLUA_DECLARE_ENCAPSULATION and wxLUA_IMPLEMENT_ENCAPSULATION
00349 //     Declare the macros used to define and implement classes that
00350 //     wrap non-wxObject derived pointers used by wxLua in the bindings.
00351 //
00352 // IMPEXPSYMBOL : similiar to WXDLLIMPEXP_WXBIND, you cannot leave this
00353 //   parameter empty, but you may use WXLUA_NO_DLLIMPEXP and
00354 //   WXLUA_NO_DLLIMPEXP_DATA(x) if you don't want DLL export symbols.
00355 // className : name of the class to encapsulate (may be NameSpace::MyClass)
00356 // objName : name to use in naming the encapsulation class (NameSpace_MyClass)
00357 // ----------------------------------------------------------------------------
00358 
00359 #define WXLUA_NO_DLLIMPEXP           // use if you don't want to export class
00360 #define WXLUA_NO_DLLIMPEXP_DATA(x) x // use if you don't want to export data
00361 
00362 #define wxLUA_DECLARE_ENCAPSULATION(IMPEXPSYMBOL, className, objName) \
00363 class IMPEXPSYMBOL wxLua_wxObject_##objName : public wxObject \
00364 { \
00365 public: \
00366     wxLua_wxObject_##objName(className *p_##objName) : m_p##objName(p_##objName) {} \
00367     virtual ~wxLua_wxObject_##objName(); \
00368     className *m_p##objName; \
00369     DECLARE_ABSTRACT_CLASS(wxLua_wxObject_##objName) \
00370 };
00371 
00372 // we may not have fully defined the class/object in header so delete it in src.
00373 #define wxLUA_IMPLEMENT_ENCAPSULATION(className, objName) \
00374 IMPLEMENT_ABSTRACT_CLASS(wxLua_wxObject_##objName, wxObject) \
00375 wxLua_wxObject_##objName::~wxLua_wxObject_##objName() \
00376 { \
00377     delete m_p##objName; \
00378 }
00379 
00380 #define wxGridCellWorkerDummyFriend wxGridCellWorkerDummyFriend; \
00381     public: \
00382     size_t GetRef() const { return m_nRef; }
00383 
00384 #define wxGridCellAttrDummyFriend wxGridCellAttrDummyFriend; \
00385     public: \
00386     size_t GetRef() const { return m_nRef; }
00387 
00388 #include "wx/grid.h"
00389 
00390 // The wxGridWorker classes have protected destructors, use DecRef().
00391 #define wxLUA_IMPLEMENT_wxGridCellWorker_ENCAPSULATION(className, objName) \
00392 IMPLEMENT_ABSTRACT_CLASS(wxLua_wxObject_##objName, wxObject) \
00393 wxLua_wxObject_##objName::~wxLua_wxObject_##objName() \
00394 { \
00395     m_p##objName->DecRef(); \
00396 }
00397 
00398 // ----------------------------------------------------------------------------
00399 // wxLuaSmartStringArray - Wraps a "new" array of wxStrings with an automatic
00400 //                         destructor that deletes them to make binding easier.
00401 // ----------------------------------------------------------------------------
00402 class WXDLLIMPEXP_WXLUA wxLuaSmartStringArray
00403 {
00404 public:
00405     wxLuaSmartStringArray(wxString *strArr = NULL) : m_strArr(strArr) { }
00406     ~wxLuaSmartStringArray() { delete[] m_strArr; }
00407 
00408     void operator = (wxString *strArr) { m_strArr = strArr; }
00409     operator const wxString *() const { return m_strArr; }
00410 
00411 private:
00412     wxString *m_strArr;
00413 };
00414 
00415 // ----------------------------------------------------------------------------
00416 // wxLuaSmartIntArray - Wraps a "new" array of ints with an automatic
00417 //                      destructor that deletes them to make binding easier.
00418 // ----------------------------------------------------------------------------
00419 class WXDLLIMPEXP_WXLUA wxLuaSmartIntArray
00420 {
00421 public:
00422     wxLuaSmartIntArray(int* intArr = NULL) : m_intArr(intArr) { }
00423     ~wxLuaSmartIntArray() { delete[] m_intArr; }
00424 
00425     void operator = (int *intArr) { m_intArr = intArr; }
00426     operator int *() { return m_intArr; } // Note: not const for wxGLCanvas
00427 
00428 private:
00429     int *m_intArr;
00430 };
00431 
00432 // ----------------------------------------------------------------------------
00433 // wxLuaSmartwxArrayString - Wraps a "new" wxArrayString with an automatic
00434 //                           destructor that deletes them to make binding easier.
00435 // ----------------------------------------------------------------------------
00436 
00437 class WXDLLIMPEXP_WXLUA wxLuaSmartwxArrayString : public wxObject
00438 {
00439 public:
00440     wxLuaSmartwxArrayString(const wxLuaSmartwxArrayString& arr) { Ref(arr); }
00441     wxLuaSmartwxArrayString(wxArrayString *arr, bool del);
00442 
00443     wxArrayString* GetArray() const;
00444 
00445     operator const wxArrayString *() const { return  GetArray(); }
00446     operator const wxArrayString &() const { return *GetArray(); }
00447     operator       wxArrayString &()       { return *GetArray(); }
00448 
00449     // You may have to cast the wxLuaSmartwxArrayString with (wxArrayString&)
00450     // e.g. wxLuaSmartwxArrayString arr; ((wxArrayString&)arr).Add(wxT("hello"));
00451     wxLuaSmartwxArrayString& operator = (const wxLuaSmartwxArrayString& arr)
00452     {
00453         Ref(arr);
00454         return *this;
00455     }
00456     wxLuaSmartwxArrayString& operator = (const wxArrayString& arr)
00457     {
00458         *GetArray() = arr;
00459         return *this;
00460     }
00461 };
00462 
00463 extern const WXDLLIMPEXP_DATA_WXLUA(wxLuaSmartwxArrayString) wxLuaNullSmartwxArrayString;
00464 
00465 // ----------------------------------------------------------------------------
00466 // wxLuaSmartwxSortedArrayString - Wraps a "new" wxSortedArrayString with an automatic
00467 //                                 destructor that deletes them to make binding easier.
00468 // ----------------------------------------------------------------------------
00469 
00470 class WXDLLIMPEXP_WXLUA wxLuaSmartwxSortedArrayString : public wxObject
00471 {
00472 public:
00473     wxLuaSmartwxSortedArrayString(const wxLuaSmartwxArrayString& arr) { Ref(arr); }
00474     wxLuaSmartwxSortedArrayString(wxSortedArrayString *arr, bool del);
00475 
00476     wxSortedArrayString* GetArray() const;
00477 
00478     operator const wxSortedArrayString *() const { return  GetArray(); }
00479     operator const wxSortedArrayString &() const { return *GetArray(); }
00480     operator       wxSortedArrayString &()       { return *GetArray(); }
00481 
00482     // You may have to cast the wxLuaSmartwxSortedArrayString with (wxSortedArrayString&)
00483     // e.g. wxLuaSmartwxSortedArrayString arr; ((wxSortedArrayString&)arr).Add(wxT("hello"));
00484     wxLuaSmartwxSortedArrayString& operator = (const wxLuaSmartwxSortedArrayString& arr)
00485     {
00486         Ref(arr);
00487         return *this;
00488     }
00489 };
00490 
00491 // ----------------------------------------------------------------------------
00492 // wxLuaSmartwxArrayInt - Wraps a "new" wxArrayInt with an automatic
00493 //                        destructor to delete them to make binding easier
00494 // ----------------------------------------------------------------------------
00495 
00496 class WXDLLIMPEXP_WXLUA wxLuaSmartwxArrayInt : public wxObject
00497 {
00498 public:
00499     wxLuaSmartwxArrayInt(const wxLuaSmartwxArrayInt& arr) { Ref(arr); }
00500     wxLuaSmartwxArrayInt(wxArrayInt *arr = NULL, bool del = true);
00501 
00502     wxArrayInt* GetArray() const;
00503 
00504     operator const wxArrayInt *() const { return  GetArray(); }
00505     operator const wxArrayInt &() const { return *GetArray(); }
00506     operator       wxArrayInt &()       { return *GetArray(); }
00507 
00508     // You may have to cast the wxLuaSmartwxArrayInt with (wxArrayInt&)
00509     // e.g. wxLuaSmartwxArrayInt arr; ((wxArrayInt&)arr).Add(5);
00510     wxLuaSmartwxArrayInt& operator = (const wxLuaSmartwxArrayInt& arr)
00511     {
00512         Ref(arr);
00513         return *this;
00514     }
00515 };
00516 
00517 // ----------------------------------------------------------------------------
00518 // wxLuaBinding - binds classes, functions, objects, and event callbacks to
00519 //                the wxLuaState.
00520 // ----------------------------------------------------------------------------
00521 
00522 // list of wxLua Bindings
00523 WX_DECLARE_USER_EXPORTED_LIST(wxLuaBinding, wxLuaBindingList, WXDLLIMPEXP_WXLUA);
00524 
00525 class WXDLLIMPEXP_WXLUA wxLuaBinding : public wxObject
00526 {
00527 public:
00528     wxLuaBinding();
00529     virtual ~wxLuaBinding() {}
00530 
00531     // Binds C Functions/Defines/Object/Events to a Lua table with binding's namespace.
00532     // The Lua table that the bindings were installed into is left on the top
00533     //   of the stack and you must pop it when done.
00534     virtual bool RegisterBinding(const wxLuaState& wxlState);
00535 
00536     // Create the metatable for the class and install it into the Lua registry.
00537     static bool InstallClassMetatable(lua_State* L, const wxLuaBindClass* wxlClass);
00538     // Install a single wxLuaBindClass struct into the table at the top
00539     // of the stack.
00540     static bool InstallClass(lua_State* L, const wxLuaBindClass* wxlClass);
00541 
00542     // -----------------------------------------------------------------------
00543 
00544     // Get/Set the binding name, a unique name of the binding.
00545     //   By default it is the "hook_cpp_namespace" used in the binding
00546     //   generator which needs to be a unique name.
00547     wxString GetBindingName() const { return m_bindingName; }
00548     void SetBindingName(const wxString& name) { m_bindingName = name; }
00549 
00550     // Get/Set the namespace table in Lua that this binding will be installed to
00551     wxString GetLuaNamespace() const { return m_nameSpace; }
00552     void SetLuaNamespace(const wxString& nameSpace) { m_nameSpace = nameSpace; }
00553 
00554     size_t GetClassCount() const        { return m_classCount; }
00555     wxLuaBindClass* GetClassArray()     { return m_classArray; }
00556 
00557     size_t GetNumberCount() const       { return m_numberCount; }
00558     wxLuaBindNumber* GetNumberArray()   { return m_numberArray; }
00559 
00560     size_t GetStringCount() const       { return m_stringCount; }
00561     wxLuaBindString* GetStringArray()   { return m_stringArray; }
00562 
00563     size_t GetEventCount() const        { return m_eventCount; }
00564     wxLuaBindEvent* GetEventArray()     { return m_eventArray; }
00565 
00566     size_t GetObjectCount() const       { return m_objectCount; }
00567     wxLuaBindObject* GetObjectArray()   { return m_objectArray; }
00568 
00569     size_t GetFunctionCount() const     { return m_functionCount; }
00570     wxLuaBindMethod* GetFunctionArray() { return m_functionArray; }
00571 
00572     // Is this wxLua type defined in this binding?
00573     bool HaswxLuaType(int wxl_type) const { return (wxl_type >= m_first_wxluatype) && (wxl_type <= m_last_wxluatype); }
00574 
00575     // -----------------------------------------------------------------------
00576     // These functions only look through the binding data of this wxLuaBinding
00577 
00578     // Find the wxLuaBindEvent with the wxEventType, returns NULL if not found.
00579     const wxLuaBindEvent* GetBindEvent(wxEventType eventType) const;
00580     // Look up the wxEventType name as a string, from the wxEventType number
00581     //  in the wxLuaBindEvent* struct list of this binding.
00582     wxString GetEventTypeName(wxEventType eventType) const;
00583     // Get the wxLuaBindClass that has this wxLua type, or NULL if none
00584     const wxLuaBindClass* GetBindClass(int wxl_type) const;
00585     // Get the wxLuaBindClass that has this name, or NULL if none
00586     const wxLuaBindClass* GetBindClass(const char* className) const;
00587     // Get the first wxLuaBindClass that has this wxLuaBindMethod
00588     const wxLuaBindClass* GetBindClass(const wxLuaBindMethod* wxlMethod) const;
00589     // Get the first wxLuaBindClass that has this wxLuaBindCFunc
00590     const wxLuaBindClass* GetBindClass(const wxLuaBindCFunc* wxlCFunc) const;
00591 
00592     // -----------------------------------------------------------------------
00593     // These functions search through the static wxLuaBinding::GetBindingList()
00594     // for the items.
00595 
00596     // Get the installed wxLuaBinding with the given
00597     //   wxLuaBinding::GetBindingName() or NULL for no match.
00598     static wxLuaBinding* GetLuaBinding(const wxString& bindingName);
00599 
00600     // Get wxLuaBindClass for given wxLua type using wxLuaBindClass::wxluatype,
00601     //   returns NULL on failure.
00602     static const wxLuaBindClass* FindBindClass(int wxl_type);
00603     // Get wxLuaBindClass that has this class name using wxLuaBindClass::name,
00604     //   returns NULL on failure.
00605     static const wxLuaBindClass* FindBindClass(const char* className);
00606     // Get the first wxLuaBindClass that has this particular wxLuaBindMethod
00607     //   returns NULL on failure.
00608     static const wxLuaBindClass* FindBindClass(const wxLuaBindMethod* wxlMethod);
00609     // Get the first wxLuaBindClass that has this particular wxLuaBindCFunc in its methods
00610     //   returns NULL on failure.
00611     static const wxLuaBindClass* FindBindClass(const wxLuaBindCFunc* wxlCFunc);
00612 
00613     // Get wxLuaBindEvent for given wxEventType (wxEvent::GetEventType()) by finding
00614     //   the matching wxLuaBindEvent::eventType.
00615     //   returns NULL on failure.
00616     static const wxLuaBindEvent* FindBindEvent(wxEventType eventType);
00617 
00618     // Get the wxLuaBinding that has this wxLuaBindMethod in its wxLuaBinding::GetFunctionArray().
00619     //   returns NULL on failure.
00620     static wxLuaBinding* FindMethodBinding(const wxLuaBindMethod* wxlMethod);
00621 
00622     // -----------------------------------------------------------------------
00623     // These functions search through the input struct
00624 
00625     // Lookup a wxLuaBindMethod function or property called methodName in the wxLuaBindClass
00626     // that is also of the wxLuaMethod_Type method_type. The method_type may be
00627     // ored values and the first match found is returned or NULL if not found.
00628     // If the wxLuaBindMethod cannot be found on the current class recurse through base classes
00629     //   if search_baseclasses.
00630     static wxLuaBindMethod* GetClassMethod(const wxLuaBindClass *wxlClass, const char *methodName,
00631                                            int method_type, bool search_baseclasses);
00632 
00633     // -----------------------------------------------------------------------
00634 
00635     // Get all the bindings that were initialized using the generated binding
00636     //   function wxLuaBinding_[binding name]_init().
00637     //   You can adjust the list *only* if you do not have any wxLuaStates
00638     //   created, otherwise the wxLua types will be out of sync.
00639     static wxLuaBindingList* GetBindingList() { return &sm_bindingList; }
00640 
00641     // -----------------------------------------------------------------------
00642 
00643     // Initialize all of the bindings by iterating the GetBindingList() and
00644     // setting the base classes and base class functions. This function
00645     // is automatically run by the wxLuaState and should not need to be called.
00646     static void InitAllBindings(bool force_update = false);
00647 
00648 protected:
00649     void InitBinding(); // must called after subclassed version is created
00650                         // to sort the bindings appropriately
00651 
00652     // Register the classes, defines, strings, events, objects, and functions
00653     // stored in the binding arrays. The Lua table to install them into
00654     // must be at the top of the stack.
00655     virtual void DoRegisterBinding(const wxLuaState& wxlState) const;
00656 
00657     // binding objects
00658     size_t           m_classCount;
00659     wxLuaBindClass*  m_classArray;
00660     size_t           m_numberCount;
00661     wxLuaBindNumber* m_numberArray;
00662     size_t           m_stringCount;
00663     wxLuaBindString* m_stringArray;
00664     size_t           m_eventCount;
00665     wxLuaBindEvent*  m_eventArray;
00666     size_t           m_objectCount;
00667     wxLuaBindObject* m_objectArray;
00668     size_t           m_functionCount;
00669     wxLuaBindMethod* m_functionArray;
00670 
00671     wxString m_bindingName;     // A unique name of the binding
00672     wxString m_nameSpace;       // Lua table namespace e.g. "wx"
00673     int m_first_wxluatype;      // The first wxLua type allocated for a class
00674     int m_last_wxluatype;       // The last wxLua type of registered classes
00675 
00676     static wxLuaBindingList sm_bindingList;
00677     static bool             sm_bindingList_initialized;
00678     static int              sm_wxluatype_max;
00679 
00680     DECLARE_ABSTRACT_CLASS(wxLuaBinding)
00681 };
00682 
00683 #endif // _WXLBIND_H_
Generated on Tue Jul 13 10:30:39 2010 for wxLua by  doxygen 1.6.3