summaryrefslogtreecommitdiff
path: root/src/BLua.cc
diff options
context:
space:
mode:
authorNicolas Noble <nnoble@blizzard.com>2013-07-24 14:23:25 -0700
committerNicolas Noble <nnoble@blizzard.com>2013-07-24 14:23:25 -0700
commit712b4bed9973c60b5c139f98e51ed804ce8a628d (patch)
tree5a634d54a49d71e1dc6091092d8a8f763403446b /src/BLua.cc
parente37ef65aaa42e790a741c15dbae9b83e9c04cd3a (diff)
Better exception handling support for Lua.
Diffstat (limited to 'src/BLua.cc')
-rw-r--r--src/BLua.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/BLua.cc b/src/BLua.cc
index 21a7452..29b68c2 100644
--- a/src/BLua.cc
+++ b/src/BLua.cc
@@ -474,12 +474,19 @@ Balau::String Balau::Lua::tostring(int i) {
struct LoadF {
Balau::IO<Balau::Handle> f;
char buff[BUFFERSIZE];
+ Balau::GeneralException * exception = NULL;
};
const char * Balau::LuaStatics::getF(lua_State * L, void * ud, size_t * size) {
LoadF * lf = (LoadF *)ud;
- *size = lf->f->read(lf->buff, BUFFERSIZE);
+ try {
+ *size = lf->f->read(lf->buff, BUFFERSIZE);
+ }
+ catch (GeneralException e) {
+ lf->exception = new GeneralException(e);
+ AssertHelper("LuaJIT is lame.");
+ }
return (*size > 0) ? lf->buff : NULL;
}
@@ -522,9 +529,15 @@ void Balau::Lua::load(IO<Handle> h, bool docall) throw (GeneralException) {
status = lua_load(L, LuaStatics::getF, &lf, name.to_charp());
if (status) {
- pushLuaContext();
- showerror();
- throw LuaException(String("Error loading lua chunk from Handle `") + h->getName() + "'");
+ if (lf.exception) {
+ GeneralException copy(*lf.exception);
+ delete lf.exception;
+ throw copy;
+ } else {
+ pushLuaContext();
+ showerror();
+ throw LuaException(String("Error loading lua chunk from Handle `") + h->getName() + "'");
+ }
}
if (docall)