lua-users home
lua-l archive

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

Luiz Henrique de Figueiredo wrote:
An other thing is that I would recommend using lua_pcall instead of lua_call.

lua_pcall is meant for when you must handle the error, for instance, by
showing a error message. lua_call is by far the most useful function; errors
that happen inside a lua_call will be automatically propagated back to the
last lua_pcall that was called before lua_call, typically the one that
initiated the whole process. This is almost always what you want and allows
for much cleaner programming. That's how the standalone interpreter works.


What I actually should have said is: "Use lua_pcall instead of lua_call
if you are not already inside execution started with lua_pcall."

I made the quess based on the original question that this might be useful
advise. The usage frequency of lua_pcall and lua_call sort of depends on if
you are embedding Lua into C or C into Lua ;-)

Is there a clean way for finding out if the program is already in pcall?

I have a C++/Lua system where certain functions are implemented in Lua or
C++ on per object basis, so it is not always clear if I am already under
pcall or not.

The other pcall problem I have mentioned in this list is that for maximum
security it seems that all the non-raw table accesses must be done under
pcall, because the metatable functions might throw an error.