From 663c41e24861ebdc14563b2c1e77d1329d11225a Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Thu, 29 Aug 2013 20:01:13 +0900 Subject: [PATCH] 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). --- Lib/lua/luarun.swg | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index e4f39e07f..dea8dd7a0 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -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 * ----------------------------------------------------------------------------- */