[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: localized errors for allocating new objects
- From: Mark Hamburg <mark@...>
- Date: Mon, 29 Mar 2010 10:21:07 -0700
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