The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

LUAUNPANIC

luaunpanic - lua wrapped into an unpanic library

DESCRIPTION

This library wraps lua so that lua's default panic behaviour (in other words: end of your application...) never happens.

The lua code base in use here is version 5.3.4.

Why this library

Because playing with abort() try catch in C is not easy, this library hides all the technical difficuly of a correct try/catch pattern in the C language over all lua methods. In addition, for those wanting to catch any lua error without this library, there is a difficulty at the very beginning: setting a try/catch handler can abort without the abort being already set... this library handles also this bootstrap case.

Wrappers semantics

  • Any function like type lua_xxx(...args...) has a wrapper like short luaunpanic_xxx(type *luaunpanic_result, ...args...).

  • Any function like void lua_xxx(...args...) has a wrapper like short luaunpanic_xxx(...args...).

Lua return code semantic is preserved and native behaviour is preserved:

  • luaunpanic wrappers always return 0 in case of success, 1 in case of failure.

  • The lua_State pointer returned with the unpanic versions of lua_State creation methods can still be used with native lua methods, available within the library.

  • A new method to retreive the latest panic string exists:

      short luaunpanic_panicstring(char **panicstringp, lua_State *L)

Wrapper usage

In other words, non-void native calls such as:

  if (lua_call(xxx)) { yyy /* failure */} else { zzz /* success */ }

should be translated to:

  if (luaunpanic_call(&luarc, xxx) || luarcrc) { yyy /* failure */ } else { zzz /* success */ }

Similary for void native lua calls:

  lua_call(xxx);

should be translated to:

  if (luaunpanic_call(xxx)) { /* failure */ }

USAGE

Obviously, this is targetting embedded lua interpreters into third-party libraries: by using luaunpanic, you make sure that your library will never exit because of lua default abort() behaviour.

SEE ALSO

Lua error handing in C