[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: PiL2, ch 28.3: Adding Lua methods to an array?
- From: "Daniel Collins" <daniel.collins@...>
- Date: Fri, 9 Jun 2006 20:19:18 +0930
> but the first parameter to the C function that implements
> methodOne is not the userdata, but the table. So the function
> fails. It would work for userdata functions that don't expect
> the userdata as the first parameter, but that is not the
> usual situation.
You could make it work if you don't mind changing the C functions that
implement the userdata. If they find a table as the first parameter on
the stack then they could query a known field in that table to see if
the actual userdata object is there. Perhaps __ud or something. Then you
could do:
local userdata = system.createUD()
local t = { __ud = userdata }
setmetatable(t, getmetatable(t.__ud))
-- call a userdata method via t
t:methodOne()
And it would work. This is not a general solution though, since it is
not always possible or desirable to modify the C code.
Cheers,
DC