summaryrefslogtreecommitdiff
path: root/src/BLua.cc
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-05 09:35:31 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-05 09:35:31 +0200
commita4312c1e04f33fd8b5f2b2649ae6aff6d31e763d (patch)
treee7fbd8e2f4a049eb34ad000a5a65ed80e1a8d710 /src/BLua.cc
parent90ef024f35c6278b246b8f659bfb1fc1dc97bfde (diff)
Improving the output of GeneralExceptions in Lua; also you can't call lua_error on a yielded co-routine.
Diffstat (limited to 'src/BLua.cc')
-rw-r--r--src/BLua.cc25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/BLua.cc b/src/BLua.cc
index 48e77d4..bed33a0 100644
--- a/src/BLua.cc
+++ b/src/BLua.cc
@@ -257,7 +257,7 @@ int Balau::LuaStatics::callwrap(lua_State * __L, lua_CFunction func) {
L.error("The C callback from Lua has thrown an EAgain - you can't do that, you have to wrap it using Lua::yield. The application will now crash, because this task will stop, but the event in the EAgain will later try to wake it up.");
}
catch (GeneralException & e) {
- L.error(String("GeneralException: ") + e.getMsg());
+ L.processException(e);
}
// LuaJIT sucks sometime.
// catch (...) {
@@ -479,10 +479,17 @@ void Balau::Lua::pushLuaContext() {
} while (!got_error);
}
-void Balau::Lua::error(const char * msg) {
+void Balau::Lua::error(const char * msg) throw (GeneralException) {
push(msg);
- lua_error(L);
+ if (yielded()) {
+ pushLuaContext();
+ showerror();
+
+ throw LuaException("Runtime error while running yielded C code.");
+ } else {
+ lua_error(L);
+ }
}
bool Balau::Lua::isobject(int i) {
@@ -845,7 +852,7 @@ bool Balau::Lua::resumeC() {
yieldedAgain = true;
}
catch (Balau::GeneralException & e) {
- error(String("GeneralException: ") + e.getMsg());
+ processException(e);
}
if (!yieldedAgain)
resume(nargs);
@@ -882,6 +889,16 @@ bool Balau::Lua::yieldC() throw (GeneralException) {
return yieldC();
}
+void Balau::Lua::processException(GeneralException & e) {
+ const char * details = e.getDetails();
+ if (details)
+ push(details);
+ auto trace = e.getTrace();
+ for (String & str : trace)
+ push(str);
+ error(String("General Exception: ") + e.getMsg());
+}
+
void Balau::Lua::showstack(int level) {
int n = lua_gettop(L);
int i;