lua-users home
lua-l archive

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


hi there! :)

ive got a general wrapper for preventing errors in callbacks that are
made inside my protected environment but put down somewhere and that
will be called from codes that are outside of my protected
environment. its a little bit tangled with my app, but the essence
looks like:

```
(function(...)
  if ... then
    print'succ'
    return select(2, ...)
  else
    print'err'
    return select(2, ...) end end)(pcall(f, args))
```
things around this should handle `f` and `args` (u can use both
`unpack()` and  `...` for `args` from an outer function, and u can
handle the error inside the anon function as u like it)

note, that its necessary to capture the return values of `pcall()`
with a function, otherwise (`{...}`) u can only check the number of
the returned args from it, or catch them, but not both... or maybe u
can, but not in 5.1! :D

ask bravely if its necessary, but now i had the mental capacity only
for this much :D

bests, have fun! :)