Murga-Projects Forums
Adding and Extending Widgets - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: Adding and Extending Widgets (/showthread.php?tid=277)


Adding and Extending Widgets - mikshaw - 02-09-2008 12:44 PM

After seeing Juergen's demonstration of extending widgets with new methods, and William's post about adding new widgets, I went back to the FLTK documentation about subclassing hoping I could translate this to murgaLua. Unfortunately I know nothing about C++ and not enough about Lua to do the translation, or even to learn if it's possible to do this with Lua.

Would anyone be willing to put forward a guess as to whether it's possible to use murgaLua to create a new subclass of Fl_Widget, maybe by putting together a collection of existing widgets?


RE: Adding and Extending Widgets - Juergen - 02-11-2008 11:08 AM

mikshaw Wrote:
After seeing Juergen's demonstration of extending widgets with new methods, and William's post about adding new widgets, I went back to the FLTK documentation about subclassing hoping I could translate this to murgaLua. Unfortunately I know nothing about C++ and not enough about Lua to do the translation, or even to learn if it's possible to do this with Lua.

Would anyone be willing to put forward a guess as to whether it's possible to use murgaLua to create a new subclass of Fl_Widget, maybe by putting together a collection of existing widgets?


No you can't do the same as in C++ just by adding or changing a few functions/methods from within Lua. But you can of course do some pseudo OO programming with Lua and it would be possible with some metatable magic and a few proxy functions to define something like subclasses (although in a limited fashion).
For example:

Code:
Fl_Menu_Bar.callback_old=Fl_Menu_Bar.callback
function Fl_Menu_Bar:callback(cb) print("New callback!") self:callback_old(cb) end

You will see the message when you call menu:callback(my_cb) but not when you call menu:add("item",0,my_cb)

There are a lot of places and quirks that have to be insert to make subclassing in Lua useful.

Although it might be interesting to do some further research.

Juergen