lua-users home
lua-l archive

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


Quoth Julio Merino <jmmv84@gmail.com>, on 2011-01-10 21:31:19 +0000:
> That's exactly what I am doing.  But, in order to prepare the pcall,
> you need to push several values onto the stack.  Pretty much all the
> lua_push* routines can still fail due to out-of-memory conditions.
> I.e. my code may end up exiting unexpectedly through the Lua panic
> routine regardless of all the efforts gone into the pcall.  (That
> said, out-of-memory situations are rare and recovering from them is
> hard, if not impossible.  So I have taken this as a reasonable risk
> and assume that this case will never happen.)

The most correct way to handle this (that I've seen) is to stuff
pointers to everything you need into a closure-esque C structure, then
use lua_cpcall, which guarantees that the call can be entered with one
light userdata and not throw from pushing on the outside.

Then you do the pushes on the inside, and then you get a headache as
you realize you can't return anything from a cpcall (which is fixed in
the slightly different mechanism in 5.2, incidentally) and you have to
stash stuff in the registry or something instead and write back to the
original C struct with the key, and...

Yeah.

   ---> Drake Wilson