[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT FFI __gc metamethod?
- From: CrazyButcher <crazybutcher@...>
- Date: Sun, 27 Feb 2011 22:05:44 +0100
I try to box the content of a cdata in my own userdata via a classic
lua plugin function, to which I can hand the metatable for the
userdata.
lua_topointer -> gives pointer to cdata obj, not the pointer it stores
lua_touserdata -> fails on cdata
lua_tonumber -> works but it feels weird
I create the number in the lua code through
tonumber(ffi.cast("uintptr_t",cdata))
and on C side
const void orig = (const void*)(uintptr_t)lua_tonumber(...)
and then I either create a userdata from the pointer directly, or
making a deepcopy
if (!size){
// store pointer value
const void** udata = lua_newuserdata(L,sizeof(void*));
udata[0] = orig;
}
else{
// deepcopy
void* udata = lua_newuserdata(L,size);
memcpy(udata,orig,size);
}
back in lua I can then cast the udata to void** and retrieve the
pointer from first case.
is that the only way to access the pointer value of cdata's data? Is
it 64 bit compatible?
will this work on simple pointer cdata and ffi.new created cdata?
Thanks for your help
-Christoph
2011/2/26 Josh Haberman <jhaberman@gmail.com>:
> Mike Pall <mikelu-1102 <at> mike.de> writes:
>> I.e. this is a difference of ~0.6 nanoseconds per dispatch for the
>> non-hoistable case. I'm not sure you'll be able to notice in
>> practice ...
>
> Just what I wanted to hear, thanks!
>
> Josh
>
>
>
- References:
- LuaJIT FFI __gc metamethod?, Josh Haberman
- Re: LuaJIT FFI __gc metamethod?, Robert G. Jakabosky
- Re: LuaJIT FFI __gc metamethod?, Josh Haberman
- Re: LuaJIT FFI __gc metamethod?, Mike Pall
- Re: LuaJIT FFI __gc metamethod?, Josh Haberman
- Re: LuaJIT FFI __gc metamethod?, Josh Haberman
- Re: LuaJIT FFI __gc metamethod?, Mike Pall
- Re: LuaJIT FFI __gc metamethod?, Josh Haberman
- Re: LuaJIT FFI __gc metamethod?, Mike Pall
- Re: LuaJIT FFI __gc metamethod?, Josh Haberman