Przeglądaj źródła

Possible error fix

Eiyeron Fulmincendii 9 lat temu
rodzic
commit
15044855f9
1 zmienionych plików z 24 dodań i 4 usunięć
  1. 24 4
      lib/luwra/functions.hpp

+ 24 - 4
lib/luwra/functions.hpp

@@ -14,6 +14,9 @@
 
 #include <functional>
 
+#include "Logger.h"
+
+
 LUWRA_NS_BEGIN
 
 /**
@@ -42,7 +45,11 @@ struct NativeFunction {
 	R operator ()() const {
 		ref.impl->push();
 
-		lua_call(ref.impl->state, 0, 1);
+		if(lua_pcall(ref.impl->state, 0, 1, 0)) {
+			WalrusRPG::Logger::error("Lua error : %s", luwra::read<const char*>(ref.impl->state, -1));
+			lua_pop(ref.impl->state, -1);
+			throw std::exception();
+		}
 		R returnValue = read<R>(ref.impl->state, -1);
 
 		lua_pop(ref.impl->state, 1);
@@ -54,7 +61,11 @@ struct NativeFunction {
 		ref.impl->push();
 		size_t numArgs = push(ref.impl->state, std::forward<A>(args)...);
 
-		lua_call(ref.impl->state, static_cast<int>(numArgs), 1);
+		if(lua_pcall(ref.impl->state, static_cast<int>(numArgs), 1, 0)) {
+			WalrusRPG::Logger::error("Lua error : %s", luwra::read<const char*>(ref.impl->state, -1));
+			lua_pop(ref.impl->state, -1);
+			throw std::exception();
+		}
 		R returnValue = read<R>(ref.impl->state, -1);
 
 		lua_pop(ref.impl->state, 1);
@@ -86,7 +97,12 @@ struct NativeFunction<void> {
 	inline
 	void operator ()() const {
 		ref.impl->push();
-		lua_call(ref.impl->state, 0, 0);
+		if(lua_pcall(ref.impl->state, 0, 0, 0)) {
+			WalrusRPG::Logger::error("Lua error : %s", luwra::read<char*>(ref.impl->state, -1));
+			lua_pop(ref.impl->state, -1);
+			throw std::exception();
+		}
+
 	}
 
 	template <typename... A> inline
@@ -94,7 +110,11 @@ struct NativeFunction<void> {
 		ref.impl->push();
 		size_t numArgs = push(ref.impl->state, std::forward<A>(args)...);
 
-		lua_call(ref.impl->state, static_cast<int>(numArgs), 0);
+		if(lua_pcall(ref.impl->state, static_cast<int>(numArgs), 0, 0)) {
+			WalrusRPG::Logger::error("Lua error : %s", luwra::read<const char*>(ref.impl->state, -1));
+			lua_pop(ref.impl->state, -1);
+			throw std::exception();
+		}
 	}
 };