lua-users home
lua-l archive

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


It be discussed long long ago :)

http://lua-users.org/lists/lua-l/2006-12/msg00285.html

2014-04-27 14:09 GMT+08:00 Karel Tuma <kat@lua.cz>:
> Hello,
>
> Just stumbled on this again (and thus have to run modified Lua),
> so I guess it's worth it to generalize this into a polyfill for portability.
>
> https://github.com/katlogic/pudata
>
> Sometimes, one needs to push existing userdata by pointer. This is not
> safe (as the pointer might be stale), therefore it is not part of core
> Lua api.
>
> This header file should be included after Lua headers - mainly because
> it overrides lua_newuserdata() with a macro, all hell would break loose
> otherwise.
>
> After that, you can push userdata by pointer. In case the userdata
> object has been collected in the meantime, nil is pushed on stack.
>
> This is handy for debugging, with native function you'd get dangling
> pointer on Lua heap. It is also very slow, so it is not a good idea
> to use this in release / performance bound code.
>
> Patching Lua(JIT) with native function is left as an excercise for the reader.
>
> -- k
>



-- 
http://blog.codingnow.com