lua-users home
lua-l archive

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


On 10/14/05, Rici Lake <lua@ricilake.net> wrote:
>
> On 14-Oct-05, at 11:34 AM, Roberto Ierusalimschy wrote:
>
> >> This is the one case in which Lua exports an internal pointer as part
> >> of its official API,
> >
> > What does it mean "the one case"? (Does it mean "the only case"?)
>
> Well, it's not really the only case. For example, lua_tostring()
> exports an internal pointer, as does lua_topointer(). I guess I meant
> that it is the only case which seems to cause problems :)

Indeed. As C programmers, we're used to the necessary evil of a
function returning a char* that will not be valid for long. But since
the other function which returns a lua_State* lets us keep it for as
long as we want--and because most "new" functions in APIs which return
pointers let us handle lifetime--it's a little surprising (though
understandable) that Lua is willing the pull the rug out from under us
in this case. Having newthread() push a thread on the stack and return
void, like newtable(), would probably be clearer, but I guess that
bird has flown. I only hope the reference manual has big flashing
lights around a description of the caveat, since it seems to come up a
lot.

Ben