I have been experimenting with changing the bindings to handle "static" functions and "enums" that are class members a little more gracefully.
Example: class MyClass { MyClass(...) int DoStuff(...) static void StaticMyClassFn(...) enum { type1, type2 } } ================= Currently we push these class items into wxLua (assume "wx" table namespace). wx.MyClass(...) = a cfunction in lua wx.MyClass_type1 = a number in lua wx.MyClass_type2 = a number in lua The function DoStuff is only accessible when you create an object, "obj = wx.MyClass(...); obj:DoStuff(...)". The static functions are a little annoying right now and you have to use the %static, %static_only or just static tag in the binding files. %static_only gets you wx.MyClass_StaticMyClassFn(...) static gets you obj = wx.MyClass(...); obj:StaticMyClassFn(...) (i.e. you must create an object in order to call the function even though the function doesn't need the object) %static gets you both wx.MyClass_StaticMyClassFn(...) and obj = wx.MyClass(...); obj:StaticMyClassFn(...) There are some wxWidgets classes where you cannot get an object of the class and so we must use the %static_only method, for other classes we might be temped to always use %static tag, but it really is overkill to have so many "global" functions in the wx table. ================== Suggested changes: A) Make the "classes" pushed into the binding table namespace (e.g. "wx") a table itself and set the metatable "__call" function to directly call the constructor function. B) Or set the metatable of the cfunctions to have __index point to the enums and static functions. Both of these two ways, A and B, allow for this calling notation in lua. wx.MyClass(...) = calls the cfunction in lua wx.MyClass.type1 = a number in lua wx.MyClass.type2 = a number in lua wx.MyClass.StaticMyClassFn(...) = a cfunction in lua Again, DoStuff() is only accessible to a created object, but now you can get at the static functions directly and access to them and the enums are more equivalent to their C++ counterparts. ISSUES with new methods: A1) The __call metatable function may take longer to run? (dunno how much) A2) Since wx.MyClass is of type() = "table" it doesn't properly register as a function and can't be used as easily as one. See http://gniemeyer.livejournal.com/tag/c and search for __call for details. A3) Takes more memory since we have to create two tables, one for the class and one for the metatable. B1) Need a metatable table, more memory then original way, but less than A. B2) Items in the metatable (static functions and enums) are kinda' "hidden" a little better than they are in A. You can examine the contents of the wx.wxRect table this way in A for k, v in pairs(wx.wxRect) do print(k, v) end In B you have to do this for k, v in pairs(getmetatable(wx.wxRect).__index) do print(k, v) end ================= Sorry about the long post, but I'm leaning towards B and wanted some thoughts on it. I've committed the code for it here http://wxlua.cvs.sourceforge.net/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp?revision=1.57&view=markup see the function wxLuaBinding::RegisterGeneratedClasses and the #if 0 statements. Note that I am not currently pushing the static functions and enums right now as they would require a change to the binding generator, so the code is more of a proof of concept. Regards, John Labenski ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users