[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Augmenting objects on per instance basis
- From: "Max van Rooij \(van Rooij Electronics Design & Software Engineering\)" <mvrooij@...>
- Date: Mon, 7 Jul 2008 20:35:28 +0200
I'm new to Lua and
very enthusiastic about it, especially in it's ability to interface with C.
I've written a GUI in C and have given the users the ability to customize
behaviours (such as mouse clicks) in Lua.
I've defined a so
called "click-able" region as a struct in C. The user can create a region that's
click-able in a lua script with a single line like this:
widget.create(100,100,10,10) --create click-able region at (x,y) = 100,100 width
10 and height 10
By implementing the
__index in C code, the user can write:
Now, the C code is
capable to relate the clicked region to the right Lua object and a get a nice
"hurray!" printed. Unfortunatly, if my user does:
I always get "left click widget 2". This is,
because the widgets share the same method table, so the last definition simply
overwrites all previous ones. How do I change my C code, so my users can have
the above code working?