just fixes

* fix battle rendering
* fix rendering glitch when following creatures
* properly throw exceptions from C++ to lua and avoid exception crashs
* fixes rendering states in framebuffer
This commit is contained in:
Eduardo Bart
2012-06-06 11:10:35 -03:00
parent 7a529d23be
commit bb1fb939c4
17 changed files with 70 additions and 90 deletions

View File

@@ -197,7 +197,7 @@ int LuaInterface::luaObjectGetEvent(LuaInterface* lua)
lua->remove(-2); // remove obj fieldmethods
if(!lua->isNil()) { // is the get method not nil?
lua->insert(-2); // moves obj to the top
lua->protectedCall(1, 1); // calls get method, arguments: obj
lua->signalCall(1, 1); // calls get method, arguments: obj
return 1;
}
lua->pop(); // pops the nil get method
@@ -242,7 +242,7 @@ int LuaInterface::luaObjectSetEvent(LuaInterface* lua)
if(!lua->isNil()) { // is the set method not nil?
lua->insert(-3); // moves func to -3
lua->insert(-2); // moves obj to -2, and value to -1
lua->protectedCall(2, 0); // calls set method, arguments: obj, value
lua->signalCall(2, 0); // calls set method, arguments: obj, value
return 0;
}
lua->pop(); // pops the nil set method
@@ -373,6 +373,15 @@ std::string LuaInterface::traceback(const std::string& errorMessage, int level)
return popString();
}
void LuaInterface::throwError(const std::string& message)
{
if(isInCppCallback()) {
pushString(message);
error();
} else
throw stdext::exception(message);
}
std::string LuaInterface::getCurrentSourcePath(int level)
{
std::string path;
@@ -425,7 +434,7 @@ int LuaInterface::safeCall(int numArgs)
return (stackSize() + numArgs + 1) - previousStackSize;
}
int LuaInterface::protectedCall(int numArgs, int requestedResults)
int LuaInterface::signalCall(int numArgs, int requestedResults)
{
int numRets = 0;
int funcIndex = -numArgs-1;
@@ -683,7 +692,7 @@ void LuaInterface::call(int numArgs, int numRets)
lua_call(L, numArgs, numRets);
}
void LuaInterface::throwError()
void LuaInterface::error()
{
assert(hasIndex(-1));
lua_error(L);

View File

@@ -153,6 +153,11 @@ public:
/// @return the generated traceback message
std::string traceback(const std::string& errorMessage = "", int level = 0);
/// Throw a lua error if inside a lua call or generates an C++ stdext::exception
/// @param message is the error message wich will be displayed before the error traceback
/// @exception stdext::exception is thrown with the error message if the error is not captured by lua
void throwError(const std::string& message);
/// Searches for the source of the current running function
std::string getCurrentSourcePath(int level = 0);
@@ -167,7 +172,7 @@ public:
/// if any error occurs it will be reported to stdout and returns 0 results
/// @param requestedResults is the number of results requested to pushes onto the stack,
/// if supplied, the call will always pushes that number of results, even if it fails
int protectedCall(int numArgs = 0, int requestedResults = -1);
int signalCall(int numArgs = 0, int requestedResults = -1);
/// @brief Creates a new environment table
/// The new environment table is redirected to the global environment (aka _G),
@@ -207,7 +212,7 @@ public:
int pcall(int numArgs = 0, int numRets = 0, int errorFuncIndex = 0);
void call(int numArgs = 0, int numRets = 0);
void throwError();
void error();
int ref();
int weakRef();
@@ -398,7 +403,7 @@ int LuaInterface::callGlobalField(const std::string& global, const std::string&
g_lua.getGlobalField(global, field);
if(!g_lua.isNil()) {
g_lua.polymorphicPush(args...);
return g_lua.protectedCall(sizeof...(args));
return g_lua.signalCall(sizeof...(args));
} else
g_lua.pop(1);
return 0;

View File

@@ -94,7 +94,7 @@ int LuaObject::callLuaField(const std::string& field, const T&... args) {
// the first argument is always this object (self)
g_lua.insert(-2);
g_lua.polymorphicPush(args...);
return g_lua.protectedCall(1 + sizeof...(args));
return g_lua.signalCall(1 + sizeof...(args));
} else {
g_lua.pop(2);
}