lua-users home
lua-l archive

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


----- Original Message ----- 
> When i pass a C function into tostring() what i get back doesn't seem to
> be the original address of the C function.  What is the value i do get and
> how ( once i have this value in my C code ) can i convert it back to the
> original C address?

The best and fastest solution I can find is:

Use lua_tocfunction to get the adress of a C function.
If you want to print it, use the "%x" format from sprintf.

Lua does the same, but uses the adress of lua_topointer, which
result adress should only be used for comparison or display, as
the manual says. So it should not be used to regain a valid
pointer.

>From what I experienced tostring does not return any adress.

Attention: the tostring in C api is different from tostring in Lua.
The Lua version (that is, if called inside the script) will generate
a string with some hexdecimal number in it, which is the adress
returned by lua_topointer on the C api.

Furthermore it seems to be very complicated to me,
if possible at all, to generate a valid C pointer out of a string.