summaryrefslogtreecommitdiff
path: root/lib/frrscript.c
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-07-24 00:17:33 +0800
committerDonald Lee <dlqs@gmx.com>2021-07-24 00:45:22 +0800
commit1da9c4bdbb5ffdaf83af482af031fa97ed47eb15 (patch)
treeda0487dbe8bc54462dfc554f827452c566aab8d8 /lib/frrscript.c
parent1763ed26559eda64663f1224a07b46001084d985 (diff)
lib: Use negative indices and add comments
Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'lib/frrscript.c')
-rw-r--r--lib/frrscript.c15
1 files changed, 12 insertions, 3 deletions
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;
}