From: John L. <jr...@us...> - 2007-06-11 03:58:15
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19140/wxLua/modules/wxlua/include Modified Files: wxlbind.h wxlstate.h Log Message: Remove wxArrayString_FromLuaTable and wxArrayInt_FromLuaTable binding tag since we convert from wxArrayInt/String automatically Fix listctrl sorting Fix validator code using wxLuaObject Rename wxLuaState::LuaCall to LuaPCall since that what it calls Lots more cleanup and shuffling of code to more appropriate places Index: wxlbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlbind.h,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** wxlbind.h 8 Jun 2007 22:50:13 -0000 1.46 --- wxlbind.h 11 Jun 2007 03:58:10 -0000 1.47 *************** *** 52,56 **** WXLUAMETHOD_OVERLOAD_BASE = 0x4000, // Class method has been checked to see if it is ! // overloaded from the base class. // Check WXLUAMETHOD::basemethod and if !NULL // this method is an overload from the base class --- 52,57 ---- WXLUAMETHOD_OVERLOAD_BASE = 0x4000, // Class method has been checked to see if it is ! // overloaded from the base class by the function ! // wxLuaBinding::GetClassMethod(wxLuaBindClass...) // Check WXLUAMETHOD::basemethod and if !NULL // this method is an overload from the base class *************** *** 80,83 **** --- 81,85 ---- int funcs_n; // number of functions (overloaded > 1) for this method wxLuaBindMethod *basemethod; // overloaded methods from base class, else NULL + // see comments for WXLUAMETHOD_OVERLOAD_BASE }; *************** *** 167,171 **** ~wxLuaFunction() {} ! int CallMethod(lua_State *L); // call WXLUAMETHOD->func(L) void *GetObject() const { return m_pObject; } --- 169,173 ---- ~wxLuaFunction() {} ! int CallMethod(lua_State *L); // call wxLuaBindMethod->func[0](L) void *GetObject() const { return m_pObject; } *************** *** 200,215 **** { public: ! // Wrap the item at the lua state's stack index. ! wxLuaObject(const wxLuaState& wxlState, int iParam = 1); virtual ~wxLuaObject(); ! // Get the value of the reference object (or a proxy if the object has ! // been aliased for a wxValidator class. bool GetObject(); // Remove any existing reference and allocate another ! void SetObject(int iParam = 1); // The following methods are used by the wxValidator interface bool *GetBoolPtr(); int *GetIntPtr(); --- 202,222 ---- { public: ! // Wrap the item at the lua state's stack index and create a reference to it. ! wxLuaObject(const wxLuaState& wxlState, int stack_idx = 1); virtual ~wxLuaObject(); ! // Get the value of the reference object and push it onto the stack. ! // (or a proxy if the object has been aliased for a wxValidator class.) ! // returns true if the object is valid and has a reference, returns false ! // on failure and nothing is pushed on the stack. bool GetObject(); // Remove any existing reference and allocate another ! void SetObject(int stack_idx = 1); // The following methods are used by the wxValidator interface + // Call GetObject() so that it's on the stack then try to get the value of + // the object as the specified type and set the member variable equal to it + // and return a pointer to member variable. bool *GetBoolPtr(); int *GetIntPtr(); *************** *** 227,231 **** private: ! wxLuaState* m_wxlState; int m_iReference; bool m_bool; --- 234,238 ---- private: ! wxLuaState* m_wxlState; // a pointer due to include recursion. int m_iReference; bool m_bool; *************** *** 326,329 **** --- 333,338 ---- virtual void UnRegisterBinding(lua_State* L); + // ----------------------------------------------------------------------- + // Get/Set the binding name, a unique name of the binding. // By default it is the "hook_cpp_namespace" used in the binding *************** *** 354,357 **** --- 363,367 ---- wxLuaBindMethod* GetFunctionArray() { return m_functionArray; } + // Is this tag defined as something in this binding? bool IsTag(int tag) { return (tag >= m_startTag) && (tag <= m_lastTag); } *************** *** 361,365 **** bool SetBaseClass(wxLuaBindClass *pClass); ! // These function only look through the binding data of this wxLuaBinding // Find the wxLuaBindEvent with the wxEventType, returns NULL if not found. --- 371,376 ---- bool SetBaseClass(wxLuaBindClass *pClass); ! // ----------------------------------------------------------------------- ! // These functions only look through the binding data of this wxLuaBinding // Find the wxLuaBindEvent with the wxEventType, returns NULL if not found. *************** *** 375,378 **** --- 386,405 ---- const wxLuaBindClass* GetLuaClass(const wxLuaBindCFunc* wxlMethod_cfunc) const; + // ----------------------------------------------------------------------- + + // Lookup a lua method or get property called cpIndex in the wxLuaBindClass array pClass + // Ensure that the lookup is of the required type. If the lua method + // can not be found on the current class recurse through base classes + // Return a pointer to the wxLuaBindMethod that corresponds to the method name, + // else return NULL; + static wxLuaBindMethod* GetClassMethod(const wxLuaBindClass *wxlClass, const char *methodName, bool search_baseclasses = true); + // Lookup a lua property function named cpIndex in the wxLuaBindClass pClass + // Ensure that the lookup is of the required type. If the lua property + // can not be found on the current class recurse through base classes + // Return a pointer to the wxLuaBindMethod that corresponds to the property name, + // else return NULL; + // Find 'Set' properties if isLuaSetProp else return 'WXLUAMETHOD_GETPROP' property + static wxLuaBindMethod* GetClassProperty(const wxLuaBindClass *wxlClass, const char *propName, bool isLuaSetProp); + // Get all the bindings that were initialized using the generated binding // function wxLuaBinding_[binding name]_init(). Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** wxlstate.h 8 Jun 2007 22:50:16 -0000 1.74 --- wxlstate.h 11 Jun 2007 03:58:10 -0000 1.75 *************** *** 87,90 **** --- 87,111 ---- }; + // ---------------------------------------------------------------------------- + // Push a special string into lua, defines to make sure it's always done the same + // ---------------------------------------------------------------------------- + + // Push the "wxLuaReferences" string onto the stack. This is the name of an + // index in the LUA_REGISTRYINDEX table that is a table indexed on the "tags" and each item + // is a metatable for classes or a reference to an object we want to keep a handle to. + #define wxlua_pushstring_wxLuaReferences(L) lua_pushlstring(L, "wxLuaReferences", 15) + // Push the "wxLuaClasses" string onto the stack. This is the name of an + // index in the LUA_REGISTRYINDEX table that is + // t[wxLuaBindClass.name] = wxLuaBindClass, where the wxLuaBindClass is a lightuserdata. + #define wxlua_pushstring_wxLuaClasses(L) lua_pushlstring(L, "wxLuaClasses", 12) + // Push the "wxLuaDerivedFunctions" string onto the stack. This is the name of an + // index in the LUA_REGISTRYINDEX table that is a table + // t[lightuserdata object] = {["derived func/value name"] = wxLuaObject(lua function/value), ...} + #define wxlua_pushstring_wxLuaDerivedFunctions(L) lua_pushlstring(L, "wxLuaDerivedFunctions", 21) + // Push the "wxLuaStateRefData" string onto the stack. This is the name of an + // index of the LUA_REGISTRYINDEX table that is a lightuserdata of the + // wxLuaStateRefData for this lua_State. + #define wxlua_pushstring_wxLuaStateRefData(L) lua_pushlstring(L, "wxLuaStateRefData", 17) + //---------------------------------------------------------------------------- // C functions for lua used by the wxLuaState *************** *** 116,120 **** WXDLLIMPEXP_WXLUA bool LUACALL wxlua_tpushusertag(lua_State* L, const void* u, int tag); // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns TLUA_NOTAG if the metatable of the object doesn't have a "tag" // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences // registry table and denotes what type of object this is. --- 137,141 ---- WXDLLIMPEXP_WXLUA bool LUACALL wxlua_tpushusertag(lua_State* L, const void* u, int tag); // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns TLUA_NOTAG if the metatable of the object doesn't have a "tag" // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences // registry table and denotes what type of object this is. *************** *** 123,128 **** // in lua to NULL so that lua won't gc it. WXDLLIMPEXP_WXLUA void* LUACALL wxlua_ttouserdata(lua_State* L, int stack_idx, bool null_ptr = false); ! // Allocate a new table (metatable) with a "tag" key equal to the number from tinsert ! // and store it in the wxLuaReferences registry table. // Returns the index into the ref table, the "tag" from tinsert. WXDLLIMPEXP_WXLUA int LUACALL wxlua_tnewtag(lua_State* L); --- 144,149 ---- // in lua to NULL so that lua won't gc it. WXDLLIMPEXP_WXLUA void* LUACALL wxlua_ttouserdata(lua_State* L, int stack_idx, bool null_ptr = false); ! // Allocate a new table (metatable) with a "tag" key equal to the number from tinsert ! // and store it in the wxLuaReferences registry table. // Returns the index into the ref table, the "tag" from tinsert. WXDLLIMPEXP_WXLUA int LUACALL wxlua_tnewtag(lua_State* L); *************** *** 131,135 **** // registry table and return its index into the ref table. WXDLLIMPEXP_WXLUA int LUACALL wxlua_tnewweaktag(lua_State* L, bool weak_keys, bool weak_values); ! // Set the metatable of the object at top of stack to the table stored in the // wxLuaReferences registry table using tget(tag). WXDLLIMPEXP_WXLUA bool LUACALL wxlua_tsettag(lua_State* L, int tag); --- 152,156 ---- // registry table and return its index into the ref table. WXDLLIMPEXP_WXLUA int LUACALL wxlua_tnewweaktag(lua_State* L, bool weak_keys, bool weak_values); ! // Set the metatable of the object at top of stack to the table stored in the // wxLuaReferences registry table using tget(tag). WXDLLIMPEXP_WXLUA bool LUACALL wxlua_tsettag(lua_State* L, int tag); *************** *** 139,153 **** lua_CFunction func, void* pClass = NULL); ! // Push the "wxLuaReferences" string onto the stack. This is the name of a ! // table in the LUA_REGISTRYINDEX that is indexed on the "tags" and each item ! // is a metatable for classes or a reference to an object we want to keep a handle to. ! #define wxlua_pushstring_wxLuaReferences(L) lua_pushlstring(L, "wxLuaReferences", 15) ! ! // Push the "wxLuaClasses" string onto the stack. This is the name of a ! // table in the LUA_REGISTRYINDEX that is t[wxLuaBindClass.name] = wxLuaBindClass ! // where the wxLuaBindClass is a lightuserdata. ! #define wxlua_pushstring_wxLuaClasses(L) lua_pushlstring(L, "wxLuaClasses", 12) ! // Verify if the luatype = lua_type(L, stack_idx) is valid for the // wxluaarg_tag which is one of the predefined WXLUAARG_XXX or s_wxluaarg_XXX types. --- 160,176 ---- lua_CFunction func, void* pClass = NULL); ! // ---------------------------------------------------------------------------- ! // Functions to get info about the tags wxlua uses to determine type ! // ---------------------------------------------------------------------------- + // Get the wxLuaBindClass* for this class_tag or NULL if the tag is invalid + WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, int class_tag); + // Get the wxLuaBindClass* for this class_name or NULL if the name is invalid + WXDLLIMPEXP_WXLUA const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, const char* class_name); + // Is a class with the class_tag equal to or derived from a class with the base_class_tag. + // 0 means same class, +1 means base is parent, +2 base is grandparent, ... + // returns -1 if the class_tag is not derived from the base class + WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(lua_State* L, int class_tag, int base_class_tag); + WXDLLIMPEXP_WXLUA int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* wxlBaseClass); // Verify if the luatype = lua_type(L, stack_idx) is valid for the // wxluaarg_tag which is one of the predefined WXLUAARG_XXX or s_wxluaarg_XXX types. *************** *** 155,158 **** --- 178,183 ---- // Note that this function does not do a direct mapping between wxlua_getwxluatype() // and wxlua_getluatype() since it allows a small amount of coersion between types. + // It also doesn't account for the automatic conversion of certain lua types + // to wxluatypes, see wxLuaState::IswxLuaType which is more complete. WXDLLIMPEXP_WXLUA int LUACALL wxlua_iswxluatype(int luatype, int wxluaarg_tag); // Get a human readable name for the predefined WXLUAARG_XXX or s_wxluaarg_XXX tags. *************** *** 190,211 **** // wxlua_isstring/numbertype definitions of what is a string or number. - // Convert the table at stack index to a "new" array of wxStrings. - // Returns a pointer to the array of wxStrings (you need to delete them) - // and returns the number of strings in the array in count. - WXDLLIMPEXP_WXLUA wxString* LUACALL wxlua_getwxStringarray(lua_State* L, int stack_idx, int& count); - // Adds the table of number indexed strings at stack index to the wxArrayString - // Return the number of strings added to the array in count. - WXDLLIMPEXP_WXLUA int LUACALL wxlua_getwxArrayString(lua_State* L, int stack_idx, wxArrayString& strArray); // Convert the table at stack index to a "new" array of const char* strings. // Return a pointer to the array of strings (you need to delete them) // returns the number of character strings in the array in count. WXDLLIMPEXP_WXLUA const char** LUACALL wxlua_getchararray(lua_State* L, int stack_idx, int& count); - // Convert the table at stack index to a "new" array of int* numbers. - // Return a pointer to the array of ints (you need to delete them) - // returns the number of ints in the array in count. - WXDLLIMPEXP_WXLUA int* LUACALL wxlua_getintarray(lua_State* L, int stack_idx, int& count); - // Adds the table at stack index to the wxArrayInt - // Return the number of ints added to the array in count. - WXDLLIMPEXP_WXLUA int LUACALL wxlua_getwxArrayInt(lua_State* L, int stack_idx, wxArrayInt& intArray); // Creates a lua table and pushes the strings into it, returns the number of items added --- 215,222 ---- *************** *** 413,420 **** // Replacement for lua_pcall that sends a wxEVT_LUA_ERROR on error ! // narg is the number of args to the function to call ! // if clear then the function is void and no return values, ! // else nresults is LUA_MULTRET to leave all of them on the stack ! int LuaCall(int narg, int clear); int LuaDoString(const wxString &script, const wxString& name = wxEmptyString) { return RunString(script, name); } int LuaDoFile(const wxString &filename) { return RunFile(filename); } --- 424,431 ---- // Replacement for lua_pcall that sends a wxEVT_LUA_ERROR on error ! // narg is the number of args to the function to call. ! // nresults is the number of values returned which lua will adjust to match ! // use LUA_MULTRET for nresults to leave all of them on the stack ! int LuaPCall(int narg, int nresults); int LuaDoString(const wxString &script, const wxString& name = wxEmptyString) { return RunString(script, name); } int LuaDoFile(const wxString &filename) { return RunFile(filename); } *************** *** 499,506 **** // Get the first wxLuaBindClass that has this particular wxLuaBindCFunc in it's methods const wxLuaBindClass* GetLuaClass(const wxLuaBindCFunc* method_cfunc) const; ! // returns true if iClassTag is derived or equal to iBaseClassTag by using // wxLuaBindClass::class_tag and wxLuaBindClass::baseclass_tag. ! // returns NULL on failure. ! bool IsDerivedClass(int iClassTag, int iBaseClassTag) const; // Get wxLuaBindEvent for given wxEventType (wxEvent::GetEventType()) by finding // the matching wxLuaBindEvent::eventType. --- 510,518 ---- // Get the first wxLuaBindClass that has this particular wxLuaBindCFunc in it's methods const wxLuaBindClass* GetLuaClass(const wxLuaBindCFunc* method_cfunc) const; ! // returns >= 0 if iClassTag is derived from or equal to iBaseClassTag by using // wxLuaBindClass::class_tag and wxLuaBindClass::baseclass_tag. ! // 0 means same class, +1 means base is parent, +2 base is grandparent, ... ! // returns -1 if the class is not derived from the base class. ! int IsDerivedClass(int iClassTag, int iBaseClassTag) const; // Get wxLuaBindEvent for given wxEventType (wxEvent::GetEventType()) by finding // the matching wxLuaBindEvent::eventType. *************** *** 581,585 **** bool tpushusertag(const void *u, int tag); // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns TLUA_NOTAG if the metatable of the object doesn't have a "tag" // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences // registry table and denotes what type of object this is. --- 593,597 ---- bool tpushusertag(const void *u, int tag); // Get the numeric tag of the object at the stack index using the metatable's "tag" key. ! // returns TLUA_NOTAG if the metatable of the object doesn't have a "tag" // key or it isn't a number. The tag is presumedly the index into the wxLuaReferences // registry table and denotes what type of object this is. *************** *** 604,607 **** --- 616,625 ---- // wxLua get data type + // Verify if the luatype = lua_type(L, stack_idx) is valid for the + // wxluaarg_tag which is one of the predefined WXLUAARG_XXX or s_wxluaarg_XXX types. + // Returns 1 if it matches, 0 if it doesn't, -1 if the wxluaarg_tag is not known. + // Note that this function does not do a direct mapping between wxlua_getwxluatype() + // and wxlua_getluatype() since it allows a small amount of coersion between types. + int IswxLuaType(int luatype, int wxluaarg_tag) const; // Check if the item at the lua stack index is user data type tag bool IsUserDataType(int stack_idx, int tag) const; *************** *** 645,657 **** // Validate that the object at the stack index specified is a table object ! // Convert the table to an array of wxStrings. This assumes that each ! // numeric entry in the table is a string object or can be converted to a string ! // Return a pointer to the array of wxStrings and set the size in count. ! // the return value wiil need to be deleted. wxString* GetStringArray(int stack_idx, int &count); ! // convert a parameter which is presumably a table into a wxArrayString. // returns the number of values in the array. int GetwxArrayString(int stack_idx, wxArrayString &strArray); ! // convert a parameter which is presumably a table into a character pointer array. // returns the number of character strings in the array in count. // You must delete the return value if not NULL. --- 663,676 ---- // Validate that the object at the stack index specified is a table object ! // or a wxArrayString and convert it to an array of wxStrings. ! // If it's a table, this assumes that each numeric entry in the table is a ! // string object or can be converted to a string. ! // Returns a pointer to a new array of wxStrings and set the size in count. ! // the return value will need to be deleted. wxString* GetStringArray(int stack_idx, int &count); ! // Convert a parameter which is either an wxArrayString or a table into a wxArrayString. // returns the number of values in the array. int GetwxArrayString(int stack_idx, wxArrayString &strArray); ! // Convert a parameter which is presumably a table into a character pointer array. // returns the number of character strings in the array in count. // You must delete the return value if not NULL. *************** *** 659,665 **** // Validate that the object at the stack index specified is a table object ! // Convert the table to an array of ints. This assumes that each ! // numeric entry in the table is a numeric object or can be converted to a number ! // Return a pointer to the array of ints and set the size in count // You must delete the return value if not NULL. int* GetIntArray(int stack_idx, int &count); --- 678,685 ---- // Validate that the object at the stack index specified is a table object ! // or a wxArrayInt and convert it to an array of ints. ! // If it's a table, this assumes that each numeric entry in the table is a ! // numeric object or can be converted to a number ! // Returns a pointer to a new array of ints and set the size in count // You must delete the return value if not NULL. int* GetIntArray(int stack_idx, int &count); *************** *** 680,700 **** wxString GetLuaTagName(int tag) const; ! // Lookup a lua method or get property called cpIndex in the wxLuaBindClass array pClass ! // Ensure that the lookup is of the required type. If the lua method ! // can not be found on the current class recurse through base classes ! // Return a pointer to the wxLuaBindMethod that corresponds to the method name, ! // else return NULL; ! wxLuaBindMethod* GetLuaMethod(const wxLuaBindClass *wxlClass, const char *methodName, bool search_baseclasses = true); ! // Lookup a lua property function named cpIndex in the wxLuaBindClass pClass ! // Ensure that the lookup is of the required type. If the lua property ! // can not be found on the current class recurse through base classes ! // Return a pointer to the wxLuaBindMethod that corresponds to the property name, ! // else return NULL; ! // Find 'Set' properties if isLuaSetProp else return 'WXLUAMETHOD_GETPROP' property ! wxLuaBindMethod* GetLuaProperty(const wxLuaBindClass *wxlClass, const char *propName, bool isLuaSetProp); // Is there a derived method given an object and and a method name. ! // If push_method then push the method onto the stack ! bool HasDerivedMethod(void *pObject, const char *method, bool push_method) const; // Find a derived method given an object and and a method name. // If the method can be found, return the wxLuaState it belongs to. --- 700,718 ---- wxString GetLuaTagName(int tag) const; ! // ----------------------------------------------------------------------- + // Add this derived method, a lua function or value the user has set to a + // wxLua userdata object that we will push onto the stack when they access + // the index of the object with the "method_name". The pObject is the + // userdata and the new wxLuaObject wraps the lua function or value + // which will be deleted by this. + bool SetDerivedMethod(void *pObject, const char *method_name, wxLuaObject* wxlObj); // Is there a derived method given an object and and a method name. ! // If push_method then push the method onto the stack. ! // A derived method is when a function or value is set to a wxLua userdata. ! bool HasDerivedMethod(void *pObject, const char *method_name, bool push_method) const; ! // When an object is being garbage collected and we call RemoveTrackedObject ! // object on it, we should also remove any derived functions or values it may have ! bool RemoveDerivedMethod(void *pObject) const; // Find a derived method given an object and and a method name. // If the method can be found, return the wxLuaState it belongs to. |