Lua has the luaL_error, and lua_error functions to be used inside a C function, like:
luaL_error( L, "something bad" );
This will cause that a error message was show and Lua execution halted. The error message will contain the line and file where it occurs:
Error: ../example/ex01.lua:6: something bad
Is there a similar function that shows the error but don't break the lua execution? but showing the line where it occurs.
LUA errors are typically caused by corrupted interface files. Resetting your User Interface should resolve the issue.
Lua assert is the function to use in the error handling of the Lua programming language. This is the function helping to handle the runtime error of the Lua source code to avoid complications between compile-time error and run time error.
Copy the source code of luaL_error and replace the call to lua_error
at the end by a suitable call to printf
using the string lua_tostring(L,-1)
. Something like this:
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));
}
Don't forget to export it to Lua by adding an entry in say base_funcs
in lbaselib.c
or by calling lua_register(L,"warn",luaB_warn)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With