lua-users home
lua-l archive

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


On Mar 29, 2010, at 9:05 AM, Roberto Ierusalimschy wrote:

> So, I guess it will boil down to this:
> 
> int pushaux (lua_State *L) {
>  lua_pushstring(L, (char *)lua_touserdata(L, 1));
>  return 1;
> }
> 
> 
> const char *ppushstring (lua_State *L, const char *s) {
>  lua_pushlightuserdata(L, s);
>  return (luaL_cpcall(L, pushaux, 1, 1) == LUA_OK) ? lua_tostring(L, -1) : NULL;
> }

Presumably one needs to check the stack space before the initial push as well, but since blowing out the stack on a push isn't supported anyway, this concern is handled elsewhere.

I will say that this pattern is really, really useful for a lot of code that has made my head hurt (until I stuck it in the sand) over the years -- e.g., C++ code that doesn't really want to know about Lua; copying values between Lua universes; etc..

Mark