summaryrefslogtreecommitdiff
path: root/library/LuaTypes.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-19 14:27:44 +0400
committerAlexander Gavrilov2012-08-19 14:27:44 +0400
commit30f71ff5106d271d04bfa26b976441cfa9b2abf6 (patch)
treeced0b058f615b90a75c495be1f4db6045100b972 /library/LuaTypes.cpp
parentb8ee52131bccd174f06c9124980bbcb8df7c80e4 (diff)
downloaddfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.gz
dfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.bz2
dfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.xz
Implement support for lua-backed viewscreens.
Diffstat (limited to 'library/LuaTypes.cpp')
-rw-r--r--library/LuaTypes.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp
index 53523c3f..e7197796 100644
--- a/library/LuaTypes.cpp
+++ b/library/LuaTypes.cpp
@@ -37,6 +37,7 @@ distribution.
#include "DataDefs.h"
#include "DataIdentity.h"
#include "LuaWrapper.h"
+#include "LuaTools.h"
#include "DataFuncs.h"
#include "MiscUtils.h"
@@ -1067,6 +1068,27 @@ int LuaWrapper::method_wrapper_core(lua_State *state, function_identity_base *id
return 1;
}
+int Lua::CallWithCatch(lua_State *state, int (*fn)(lua_State*), const char *context)
+{
+ if (!context)
+ context = "native code";
+
+ try {
+ return fn(state);
+ }
+ catch (Error::NullPointer &e) {
+ const char *vn = e.varname();
+ return luaL_error(state, "%s: NULL pointer: %s", context, vn ? vn : "?");
+ }
+ catch (Error::InvalidArgument &e) {
+ const char *vn = e.expr();
+ return luaL_error(state, "%s: Invalid argument; expected: %s", context, vn ? vn : "?");
+ }
+ catch (std::exception &e) {
+ return luaL_error(state, "%s: C++ exception: %s", context, e.what());
+ }
+}
+
/**
* Push a closure invoking the given function.
*/