diff --git a/lib/frrscript.c b/lib/frrscript.c index 3f2544f4a0..8fe8a93f05 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -208,10 +208,14 @@ void *frrscript_get_result(struct frrscript *fs, const char *function_name, if (lfs == NULL) return NULL; - /* results table is idx 1 on the stack, getfield pushes our item to idx - * 2 + /* At this point, the Lua state should have only the returned table. + * We will then search the table for the key/value we're interested in. + * Then if the value is present (i.e. non-nil), call the lua_to* + * decoder. */ - lua_getfield(lfs->L, 1, name); + assert(lua_gettop(lfs->L) == 1); + assert(lua_istable(lfs->L, -1) == 1); + lua_getfield(lfs->L, -1, name); if (lua_isnil(lfs->L, -1)) { lua_pop(lfs->L, 1); zlog_warn( @@ -221,6 +225,11 @@ void *frrscript_get_result(struct frrscript *fs, const char *function_name, } p = lua_to(lfs->L, 2); + /* At the end, the Lua state should be same as it was at the start + * i.e. containing soley the returned table. */ + assert(lua_gettop(lfs->L) == 1); + assert(lua_istable(lfs->L, -1) == 1); + return p; }