Murga-Projects Forums

Full Version: Clearing up an incorrect asumption ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

A while ago Juergen posted the following :

Juergen Wrote:
I didn't look into the code, but when I saw the double quotes in the original example it looked like you are compiling a binary chunk and calling it later.

I have an alternative suggestion. A few weeks ago I did a small user_data replacement implementation in pure Lua:



function Fl_Button:user_data(...)
local arg={...}
if #arg<1 then return self.udata[self]
   else self.udata[self]=arg[1]

It is simple, works with all values (also functions or tables). I guess it isn't hard to do it in C++ with some metatable magic and hide the table somewhere.


I wanted to clear this up, as it is potentially very dangerous ...

When you reference "self" in this way for murgaLua FLTK objects you are referring to the "UserData" that represents the instance of the Object you are looking at. The problem is that in murgaLua I use lightweight versions that just provide a reference back to the original instance ...

Note that I said they "provide" as reference as to "being" a reference, the difference is important, as Juergen is assuming that every time he gets his hands on the same widget the "self/UserData" will be same ... But it most likely won't ...

The underlying reference will be, but the "UserData" that provides it won't be.

I am surprised someone hasn't realized this doesn't work, as under any kind of strain this kinda code would break.

However, I understand what Juergen is trying to do, and it is actually a very good idea, with this in mind I have provided a "serial()" method, that returns a representation of the underlying reference and CAN be used as uniquely identifying key for a widget table.

The new menu example shows the UserData behaviour I have described here, as well as the use of the "serial()" method.

As for extending widgets ... I'll write a tutorial soon ;-)


Reference URL's