[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Please comment on these Lua to C library bindings that I wrote
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 20 Nov 2012 11:15:38 +0200
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.