diff options
author | Quentin Young <qlyoung@nvidia.com> | 2020-11-29 20:51:52 +0100 |
---|---|---|
committer | Quentin Young <qlyoung@nvidia.com> | 2020-12-02 00:37:14 +0100 |
commit | 9e47ee98a3de9c7c3f6ee4eb527f59015a5515b5 (patch) | |
tree | b783a74b8f1914c228af1123a03a085c2da94c2b | |
parent | lib: better load-time error handling for scripts (diff) | |
download | frr-9e47ee98a3de9c7c3f6ee4eb527f59015a5515b5.tar.xz frr-9e47ee98a3de9c7c3f6ee4eb527f59015a5515b5.zip |
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 <qlyoung@nvidia.com>
-rw-r--r-- | bgpd/bgp_routemap.c | 2 | ||||
-rw-r--r-- | lib/frrlua.c | 17 | ||||
-rw-r--r-- | lib/frrlua.h | 12 | ||||
-rw-r--r-- | lib/frrscript.c | 7 | ||||
-rw-r--r-- | lib/frrscript.h | 3 |
5 files changed, 13 insertions, 28 deletions
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 247391ade..b296c86a1 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 eeac98ccd..f768575b6 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 029e6ecee..6e646e337 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 <lua.h> +#include <lualib.h> +#include <lauxlib.h> #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 bc6d07581..f4b696709 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 39eebe6e4..21cd35288 100644 --- a/lib/frrscript.h +++ b/lib/frrscript.h @@ -19,6 +19,7 @@ #ifndef __FRRSCRIPT_H__ #define __FRRSCRIPT_H__ +#include <lua.h> #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 */ |