[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Userdata/Table Unification
- From: Rici Lake <lua@...>
- Date: Mon, 26 Jul 2004 11:59:51 -0500
Alternative implementation, which is not quite so "unified":
Add a peertable field to every full userdata, and modify lua_raw{get,
set, geti, seti} to transparently reference this table, if it exists.
(But not the Lua base library raw* functions.)
I have experimented with a simple patch which does this, and it seems
quite adequate to the purpose. The actual implementation I use adds two
pointers to a userdata: a Lua table, and a void*; the latter is the "C
peer". The Cpeer field can be used to hold boxed pointers, which avoids
increasing the size of userdatas which only hold boxed pointers.
I believe this addresses Virgil's (and my) sandboxing requirements and
also solves many of the issues around associating Lua objects with
userdata. In particular, it allows the use of the userdata's metatable
for class identification because instance-specific Lua objects can be
held in the peer table.
The use of lua_raw* limits API explosion (although the API does need to
be expanded to allow setting and getting peer information) and also
"feels" quite natural in practice.
Patch (for 5.0.2) available upon request.
Rici