Fix check for errors when compiling MoonScript

This commit is contained in:
Thomas Goyne 2013-05-09 06:27:35 -07:00
parent 536cff7cb6
commit f76b9ff356
2 changed files with 14 additions and 4 deletions

View File

@ -436,7 +436,7 @@ namespace Automation4 {
// load user script
if (!LoadFile(L, GetFilename())) {
std::string err = str(boost::format("Error loading Lua script \"%s\":\n\n%s") % GetPrettyFilename().string() % get_string_or_default(L, -1));
std::string err = str(boost::format("Error loading Lua script \"%s\":\n\n%s") % GetPrettyFilename().string() % get_string_or_default(L, 1));
lua_pop(L, 1);
throw ScriptLoadError(err);
}
@ -556,7 +556,7 @@ namespace Automation4 {
try {
if (!LoadFile(L, path))
return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", path.string().c_str(), luaL_checkstring(L, -1));
return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", path.string().c_str(), luaL_checkstring(L, 1));
break;
}
catch (agi::fs::FileNotFound const&) {
@ -595,7 +595,7 @@ namespace Automation4 {
return luaL_error(L, "Lua include not found: %s", filename.c_str());
if (!LoadFile(L, filepath))
return luaL_error(L, "Error loading Lua include \"%s\":\n\n%s", filename.c_str(), luaL_checkstring(L, -1));
return luaL_error(L, "Error loading Lua include \"%s\":\n\n%s", filename.c_str(), luaL_checkstring(L, 1));
int pretop = lua_gettop(L) - 1; // don't count the function value itself
lua_call(L, 0, LUA_MULTRET);

View File

@ -58,6 +58,16 @@ namespace Automation4 {
return false; // Leaves error message on stack
lua_pushlstring(L, &buff[0], buff.size());
lua_pushstring(L, filename.string().c_str());
return lua_pcall(L, 2, 1, 0) == 0; // Leaves script or error message on stack
if (lua_pcall(L, 2, 2, 0))
return false; // Leaves error message on stack
// loadstring returns nil, error on error or a function on success
if (lua_isnil(L, 1)) {
lua_remove(L, 1);
return false;
}
lua_pop(L, 1); // Remove the extra nil for the stackchecker
return true;
}
}