Copy the source code of luaL_error and replace the call with lua_error at the end with the appropriate call to printf using the line lua_tostring(L,-1) . Something like that:
LUALIB_API int luaL_warn (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); printf("warning: %s\n",lua_tostring(L,-1)); return 0; } static int luaB_warn (lua_State *L) { return luaL_warn(L, "%s", luaL_checkstring(L, 1)); }
Remember to export it to Lua by adding an entry to the base_funcs text in lbaselib.c or by calling lua_register(L,"warn",luaB_warn) .
source share