[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: pcall & require?
- From: Tomas <tomas@...>
- Date: Wed, 23 Feb 2005 08:31:29 -0300 (BRST)
On Wed, 23 Feb 2005, PA wrote:
> If anything unexpected happens in Main.lua, the interpreter exits,
> right? I would like to avoid this. How?
You should use pcall or xpcall (if you want to customize
the error message). CGILua has the same problem while running the
configuration file, or executing the opening functions, or executing
the requested script... It manages to solve this by creating its own
pcall, which redefines the error message and throws the error correctly:
function pcall (f, ...)
local result = pack (xpcall (function () return f(unpack(arg)) end,
if not result then
return unpack (result)
errorhandler() is the function responsible for formatting
the error message; erroroutput is the function responsible for the
output (it could write it to the log or to the browser ...). Both
functions could be redefined by the user.
cgilua.pcall() uses xpcall() to redefine the error message
function generator. However the arguments to the call cannot be passed
as regular arguments so CGILua has to create another function just to
call f() with the proper arguments.
I hope this will help you,