From 9e47ee98a3de9c7c3f6ee4eb527f59015a5515b5 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Sun, 29 Nov 2020 14:51:52 -0500 Subject: [PATCH] lib: cleanup / refactor scripting foo - fix 'struct lua_State' - change includes to library style - rename encoder funcs to look like lua_push* funcs - fix erroneous doc comment on prefix encoder - remove unused (and broken) convenience func Signed-off-by: Quentin Young --- bgpd/bgp_routemap.c | 2 +- lib/frrlua.c | 17 ++--------------- lib/frrlua.h | 12 +++++------- lib/frrscript.c | 7 +++---- lib/frrscript.h | 3 ++- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 247391adef..b296c86a1e 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -394,7 +394,7 @@ route_match_command(void *rule, const struct prefix *prefix, void *object) /* * Setup the prefix information to pass in */ - frrlua_newtable_prefix(L, prefix); + lua_pushprefix(L, prefix); /* * Setup the bgp_path_info information */ diff --git a/lib/frrlua.c b/lib/frrlua.c index eeac98ccd8..f768575b66 100644 --- a/lib/frrlua.c +++ b/lib/frrlua.c @@ -37,19 +37,6 @@ * stack easier. */ -const char *frrlua_table_get_string(lua_State *L, const char *key) -{ - const char *str; - - lua_pushstring(L, key); - lua_gettable(L, -2); - - str = (const char *)lua_tostring(L, -1); - lua_pop(L, 1); - - return str; -} - int frrlua_table_get_integer(lua_State *L, const char *key) { int result; @@ -70,7 +57,7 @@ int frrlua_table_get_integer(lua_State *L, const char *key) * datatypes. */ -int frrlua_newtable_prefix(lua_State *L, const struct prefix *prefix) +int lua_pushprefix(lua_State *L, const struct prefix *prefix) { char buffer[100]; @@ -87,7 +74,7 @@ int frrlua_newtable_prefix(lua_State *L, const struct prefix *prefix) return 0; } -int frrlua_newtable_interface(lua_State *L, const struct interface *ifp) +int lua_pushinterface(lua_State *L, const struct interface *ifp) { zlog_debug("frrlua: pushing interface table"); diff --git a/lib/frrlua.h b/lib/frrlua.h index 029e6ecee8..6e646e337d 100644 --- a/lib/frrlua.h +++ b/lib/frrlua.h @@ -21,9 +21,9 @@ #if defined(HAVE_LUA) -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" +#include +#include +#include #include "prefix.h" #include "frrscript.h" @@ -34,15 +34,13 @@ extern "C" { /* * Pushes a new table containing relevant fields from a prefix structure. - * - * Additionally sets the global variable "prefix" to point at this table. */ -int frrlua_newtable_prefix(lua_State *L, const struct prefix *prefix); +int lua_pushprefix(lua_State *L, const struct prefix *prefix); /* * Pushes a new table containing relevant fields from an interface structure. */ -int frrlua_newtable_interface(lua_State *L, const struct interface *ifp); +int lua_pushinterface(lua_State *L, const struct interface *ifp); /* * Retrieve a string from table on the top of the stack. diff --git a/lib/frrscript.c b/lib/frrscript.c index bc6d075810..f4b696709a 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -220,8 +220,7 @@ void frrscript_init() "Lua type encoders"); /* Register core library types */ - frrscript_register_type_encoder("prefix", - (encoder_func)frrlua_newtable_prefix); - frrscript_register_type_encoder( - "interface", (encoder_func)frrlua_newtable_interface); + frrscript_register_type_encoder("prefix", (encoder_func)lua_pushprefix); + frrscript_register_type_encoder("interface", + (encoder_func)lua_pushinterface); } diff --git a/lib/frrscript.h b/lib/frrscript.h index 39eebe6e46..21cd352881 100644 --- a/lib/frrscript.h +++ b/lib/frrscript.h @@ -19,6 +19,7 @@ #ifndef __FRRSCRIPT_H__ #define __FRRSCRIPT_H__ +#include #include "frrlua.h" #ifdef __cplusplus @@ -27,7 +28,7 @@ extern "C" { #define FRRSCRIPT_PATH "/etc/frr/scripts" -typedef int (*encoder_func)(struct lua_State *, const void *); +typedef int (*encoder_func)(lua_State *, const void *); struct frrscript { /* Script name */ -- 2.39.5