I have been searching high and low for a way to handle errors with the C API for Lua, and simply print them out in the console. Though, I'm unable to find a single working example. What I would like to do is simply something like:
static int test(lua_State *L)
{
if(!lua_isstring(L, 1))
return luaL_error(L, "This is not a valid string");
}
or
static int test(lua_State *L)
{
try
{
if (!lua_isstring(L, 1))
{
throw luaL_error(L, "This is not a valid string");
}
}
catch (int e)
{
std::cout << "Error " << e << std::endl;
}
}
But nothing works as up to this point. What would be the correct way to do the error handling with the LUA C API and show messages in the console?