--- a/src/nexus_lua.c Sun Apr 19 06:20:59 2009 +0300
+++ b/src/nexus_lua.c Sun Apr 19 23:53:37 2009 +0300
@@ -72,33 +72,35 @@
err_t nexus_lua_eval (struct nexus_lua *lua, const char *chunk, struct error_info *err)
{
int ret;
+ bool loaded = false;
+
+ RESET_ERROR(err);
// load the line as a lua function
if ((ret = luaL_loadstring(lua->st, chunk)))
goto error;
+
+ loaded = true;
// execute it
- if ((ret = lua_pcall(lua->st, 0, 0, 0))) {
- // pop off the bad chunk
+ if ((ret = lua_pcall(lua->st, 0, 0, 0)))
+ goto error;
+
+error:
+ if (ret) {
+ // build the error_info
+ nexus_lua_error(lua->st, ret, err);
+
+ // pop it
+ // XXX: err points at GC:able memory
lua_pop(lua->st, 1);
-
- goto error;
}
- // ok, pop off the chunk
- lua_pop(lua->st, 1);
-
- // done
- return SUCCESS;
+ if (loaded) {
+ // pop off the chunk
+ lua_pop(lua->st, 1);
+ }
-error:
- // build the error_info
- nexus_lua_error(lua->st, ret, err);
-
- // pop it
- lua_pop(lua->st, -1);
-
- // XXX: err points at GC:able memory
return ERROR_CODE(err);
}