[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: light userdata (Was: Fastest way to transfer data from C to Lua ?)
- From: Philipp Janda <siffiejoe@...>
- Date: Sun, 09 Jun 2013 19:42:59 +0200
Am 09.06.2013 17:26 schröbte Kevin Martin:
On 9 Jun 2013, at 12:05, Tim Hill wrote:
so it is of limited use unless the pointer is to static memory or heap memory that will not be released until after the Lua state is closed. I'm with you.
This isn't true if the light userdata are stored in a table which has a gc metamethod to call the appropriate free function.
I hardly ever use full userdata as an object, but instead use a table and put light userdata in it. I find it much more flexible than full userdata.
But then you need to maintain a set of valid userdata handles for each
class to make it safe, or else:
local o1, o2 = class1.new(), class2.new()
o1.udata, o2.udata = o2.udata, o1.udata
... and __gc for tables only works in Lua 5.2 and up.