2011-08-14 04:09:11 +02:00
|
|
|
#include "luaexception.h"
|
|
|
|
#include "luainterface.h"
|
|
|
|
|
|
|
|
LuaException::LuaException(const std::string& error, int traceLevel)
|
|
|
|
{
|
|
|
|
g_lua.clearStack(); // on every exception, clear lua stack
|
|
|
|
generateLuaErrorMessage(error, traceLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaException::generateLuaErrorMessage(const std::string& error, int traceLevel)
|
|
|
|
{
|
|
|
|
// append trace level to error message
|
|
|
|
if(traceLevel >= 0)
|
2011-08-15 16:06:15 +02:00
|
|
|
m_what = fw::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel));
|
2011-08-14 04:09:11 +02:00
|
|
|
else
|
2011-08-15 16:06:15 +02:00
|
|
|
m_what = fw::mkstr("LUA ERROR: ", error);
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
|
|
|
|
{
|
|
|
|
std::string error = "attempt to call a function with wrong number of arguments";
|
|
|
|
if(expected >= 0 && got >= 0)
|
2011-08-15 16:06:15 +02:00
|
|
|
error = fw::mkstr(error, " (expected ", expected, ", but got ", got, ")");
|
2011-08-14 04:09:11 +02:00
|
|
|
generateLuaErrorMessage(error, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
|
|
|
|
{
|
2011-08-15 16:06:15 +02:00
|
|
|
std::string error = fw::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
|
2011-08-14 04:09:11 +02:00
|
|
|
generateLuaErrorMessage(error, 0);
|
|
|
|
}
|