lua-users home
lua-l archive

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


2012/11/20 Richard W.M. Jones <rjones@redhat.com>:

>
> - How do I push a userdata onto the Lua stack?  Instead I'm pushing
>   a pointer to a userdata using: lua_pushlightuserdata (L, u);
>

That's all you can do. One-way traffic only. The manual says:
-----
const void *lua_topointer (lua_State *L, int index);

Converts the value at the given acceptable index to a generic C
pointer (void*). The value can be a userdata, a table, a thread, or a
function; otherwise, lua_topointer returns NULL. Different objects
will give different pointers.
There is no way to convert the pointer back to its original value.
----

You have two ways of returning a full userdata.

1. Created it with lua_newuserdata.
2. It was one of the arguments received, and it is one of the values returned.