[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Object oriented access of c++ objects in lua
- From: Mark Hamburg <mhamburg@...>
- Date: Tue, 10 Aug 2004 10:27:05 -0700
on 8/10/04 7:58 AM, Virgil Smith at Virgil@Nomadics.com wrote:
> 2. Supply a Lua table as the object instance rather than supplying the
> userdata directly, fill in the table with function closures for your
> methods. Each closure should be given an upvalue that references your
> userdata. Since the userdata itself is not directly accessed by Lua code it
> can be either a full userdata or a light userdata, however, only a full
> userdata can have a metatable and __gc metamethod. In this way your methods
> can have access to both the C side data (the userdata upvalue) AND the per
> instance Lua data (the table itself). However, the __gc metamethod won't
> have access to the Lua data.
3 (or 2b): Supply a table with either a direct link to your userdata or a
link through a hidden weak-keyed table. Your methods attach to the table and
need to go find the userdata. If you are writing trampolines to member
functions in C++ or methods in Objective-C, you can actually have the
trampoline do the work so that this/self points to the native object and the
first entry in the Lua stack frame references the table.
Mark