[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can full userdata be put back on the stack?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 7 Dec 2002 09:47:52 -0200
>In Lua5.0 say I want a C function that takes full userdata (containing
>an int) as a parameter, uses it (but does not modify it) then returns
>userdata containing an int of the same value as was passed in. Should
>I create new full userdata (with lua_newuserdata(sizeof(int)) and copy
>the data over, or is it recommended to push the same userdata as was
>passed in on the stack (perhaps with lua_pushlightuserdata)?
It depends on whether you want the same value returned or a different value.
If it's the same value, you can use lua_pushvalue to put it on the stack to
be returned. If your function only expects a single argument and only returns
a single result, you can just "return 1"; no need to push it again.