lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 16-May-05, at 2:36 PM, Chris Marrin wrote:

Ben Sunshine-Hill wrote:
...

Yes, this is just about the code I came up with (without the erroneous newudata), by patterning after lua_newuserdata(). I am not very happy about subverting Lua like this either, except that I really need the performance boost and I REALLY, REALLY promise that the pointer will always be good :-)

If you don't want to go hacking the Lua core, I have another solution...

You say you're reffing the new userdata anyway; this is going to store a reference in the registry. There's no magic to luaL_ref other than that. So why not kill two birds with one stone?

Instead of using luaL_ref to store a reference in the registry, store your own reference in the registry using a lightuserdata of the this pointer as a key. Then you can push the lua object onto the stack using the this pointer, without breaking the API and without incurring much overhead (since the hash of a lud is essentially the address).

R.