Add Lua runtime helper functions for error-handling

Add two helper functions to the Lua runtime, "SWIG_Lua_pusherrstring"
and "SWIG_Lua_pushferrstring".

These are like the standard Lua functions lua_pushstring and
lua_pushfstring respectively, except that the strings are prefixed
with the location of the innermost Lua call-point (as generated by
luaL_where).
This commit is contained in:
Miles Bader 2013-08-29 20:01:13 +09:00 committed by William S Fulton
commit 663c41e248

View file

@ -71,6 +71,36 @@ extern "C" {
#endif
/* --------------------------------------------------------------------------
* Helper functions for error handling
* -------------------------------------------------------------------------- */
/* Push the string STR on the Lua stack, like lua_pushstring, but
prefixed with the the location of the innermost Lua call-point
(as formated by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
{
luaL_where (L, 1);
lua_pushstring (L, str);
lua_concat (L, 2);
}
/* Push a formatted string generated from FMT and following args on
the Lua stack, like lua_pushfstring, but prefixed with the the
location of the innermost Lua call-point (as formated by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
luaL_where(L, 1);
lua_pushvfstring(L, fmt, argp);
va_end(argp);
lua_concat(L, 2);
}
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */