|
Max, It's hard to figure out exactly how you've implemented the widget object produced by widget.create() Is it a Lua table, or a Lua userdata object? Personally I would choose a userdata object, defined (loosely) as struct widget { int x, y, w, h; // hot spot int values; // lua values associated with this widget }; 'values' would contain a value produced by 'luaL_ref', which refers to a table. The metatable for the userdata object would implement the following functions: __index: looks up values in the table referred to by 'values', and potentially in a shared table as well. You can store this table in the registry. __newindex: stores value in the table referred to by 'values', indexed by key. __gc: calls luaL_unref on 'value' to allow collection of the table. If you keep the 'widget' structure in a linked list this is the routine that should remove it. The routine that dispatches the left click should identify the correct 'widget', get the table associated with the widget, get the 'leftclick' value, and if it's not nil call it with the widget as its first argument. I've attached some crude sample code. |
Attachment:
widget.c
Description: Binary data
Attachment:
test.lua
Description: Binary data
Groetjes, Gé On Jul 7, 2008, at 11:35 AM, Max van Rooij (van Rooij Electronics Design & Software Engineering) wrote:
-- Gé Weijers |