lua-users home
lua-l archive

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


Hi,

Robert Raschke wrote:
> function foo()
> 	assert(nil, "an error")
> end
> 
> dofile("conf")
> 
> And the file conf just says "foo{}", then I'd like to get an error
> 
> .../conf:1: an error
> 
> instead of
> 
> .../main.lua:3: an error

See the section in the manual about the error() function.

> Is there an easy way to do this?

function assert3(ok, ...)
  if not ok then
    error(..., 3)
  end
  return ok, ...
end

Requires Lua 5.1 due to the '...' syntax (but can be implemented
without it, too).

Bye,
     Mike