lua-users home
lua-l archive

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

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

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

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;
    // deepcopy
    void* udata = lua_newuserdata(L,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 created cdata?

Thanks for your help


2011/2/26 Josh Haberman <>:
> Mike Pall <mikelu-1102 <at>> 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