Shea Martin wrote:
If my embedded interpreter encounters an error in the script,
during the
dofile() routine, it just punts. dofile return a value of 1,
so I know an error was encountered, but I have no idea what
the error was. There is no error message printed, etc.
Is there any sort of way to determine what is wrong with my
script, and print a message to the user?
I don't think lua_pcall() is what I want, as it calls a
function. I am still loading the script.
As you can see in its doc luaL_dofile is defined as:
luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))
It is then equivalent to a lua_pcall if loadfile suceeds. As you can see
in the documentation of luaL_loadfile and lua_pcall, if there is an
error on any of these functions it is left on top of the stack as a
string. To simply print it do the following:
int somefunction(lua_State* L)
{
if (luaL_dofile(L, "myscript.lua"))
{
printf("%s\n", lua_tostring(L, -1));
}
return 0;
}