diff --git a/smmapdfw/lua_worker.c b/smmapdfw/lua_worker.c index f3bdc3b..8d80b23 100644 --- a/smmapdfw/lua_worker.c +++ b/smmapdfw/lua_worker.c @@ -172,10 +172,9 @@ int lua_work(void *handle, void *work_handle, char *input, char *output) { res = lua_pcall(lwh->l, 1, 2, 0); - lua_output = (char*) lua_tostring(lwh->l, lua_gettop(lwh->l)); - lua_pop(lwh->l, 1); + /* peek the result from the stack */ + lua_output = (char*) lua_tostring(lwh->l, lua_gettop(lwh->l)); result = lua_tonumber(lwh->l, lua_gettop(lwh->l)); - lua_pop(lwh->l, 1); if (0 != res) { syslog(LOG_ERR, "lua_work: error when calling entrypoint function: %d", res); @@ -185,5 +184,8 @@ int lua_work(void *handle, void *work_handle, char *input, char *output) { snprintf(output, ANSWER_BUFSIZE, lua_output); } + /* remove the result from the stack */ + lua_pop(lwh->l, 2); + return result; }