summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-08-23 13:24:37 +0200
committersapier <Sapier at GMX dot net>2014-08-23 20:53:34 +0200
commite09293b483fcfb5a2095d4bfeccae57153df6250 (patch)
tree33e9bad78d9f11a5bed95006fb5df6c9fae2413c /src/script
parent3e267a6ece99b0affa1e0d5c15fb21c1b60dd63d (diff)
downloadminetest-e09293b483fcfb5a2095d4bfeccae57153df6250.tar.gz
minetest-e09293b483fcfb5a2095d4bfeccae57153df6250.tar.bz2
minetest-e09293b483fcfb5a2095d4bfeccae57153df6250.zip
Add lua exception handling test code
Catch some error situations when mod used without thinking about it
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_server.cpp35
-rw-r--r--src/script/lua_api/l_server.h5
2 files changed, 40 insertions, 0 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 76fe439eb..8d7f6512e 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "environment.h"
#include "player.h"
+#include "log.h"
// request_shutdown()
int ModApiServer::l_request_shutdown(lua_State *L)
@@ -449,6 +450,36 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
return 0;
}
+#ifndef NDEBUG
+// cause_error(type_of_error)
+int ModApiServer::l_cause_error(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ std::string type_of_error = "none";
+ if(lua_isstring(L, 1))
+ type_of_error = lua_tostring(L, 1);
+
+ errorstream << "Error handler test called, errortype=" << type_of_error << std::endl;
+
+ if(type_of_error == "segv") {
+ volatile int* some_pointer = 0;
+ errorstream << "Cause a sigsegv now: " << (*some_pointer) << std::endl;
+
+ } else if (type_of_error == "zerodivision") {
+
+ unsigned int some_number = porting::getTimeS();
+ unsigned int zerovalue = 0;
+ unsigned int result = some_number / zerovalue;
+ errorstream << "Well this shouldn't ever be shown: " << result << std::endl;
+
+ } else if (type_of_error == "exception") {
+ throw BaseException("Errorhandler test fct called");
+ }
+
+ return 0;
+}
+#endif
+
void ModApiServer::Initialize(lua_State *L, int top)
{
API_FCT(request_shutdown);
@@ -475,4 +506,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(kick_player);
API_FCT(unban_player_or_ip);
API_FCT(notify_authentication_modified);
+
+#ifndef NDEBUG
+ API_FCT(cause_error);
+#endif
}
diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h
index 4101f2856..fd85a8975 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -88,6 +88,11 @@ private:
// notify_authentication_modified(name)
static int l_notify_authentication_modified(lua_State *L);
+#ifndef NDEBUG
+ // cause_error(type_of_error)
+ static int l_cause_error(lua_State *L);
+#endif
+
public:
static void Initialize(lua_State *L, int top);