lua-users home
lua-l archive

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


> I'm thinking what would be nice is if error() (and the C versions like
> lua_error) could return more than just a text message.

This is already possible: you can use any Lua value as the "message".
In particular, you can send a complex error message by using a table.
Try this:

  function f() error(print) end
  print(print,pcall(f))

and this:

  function f(x) error(x) end
  function try(x) print(x,pcall(f,x)) end

  try()
  try(1)
  try(nil)
  try("bye")
  try(try)
  try{}
  try(io.stdout)

--lhf