]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: cleanup / refactor scripting foo
authorQuentin Young <qlyoung@nvidia.com>
Sun, 29 Nov 2020 19:51:52 +0000 (14:51 -0500)
committerQuentin Young <qlyoung@nvidia.com>
Tue, 1 Dec 2020 23:37:14 +0000 (18:37 -0500)
- 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>
bgpd/bgp_routemap.c
lib/frrlua.c
lib/frrlua.h
lib/frrscript.c
lib/frrscript.h

index 247391adef8afa22e92bb0ec6c0c788a60b8bfaf..b296c86a1ec6a4f340232f2a0d59de663814fae3 100644 (file)
@@ -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
         */
index eeac98ccd8ab70fe2af259e1a41fa675bd558903..f768575b6610d3d6ab5decfad4e74b3975dba136 100644 (file)
  * 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");
 
index 029e6ecee84d26b07c116fa6c4f55b48f1315d91..6e646e337d53a6d17acb28766800861ee0f9d3f6 100644 (file)
@@ -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.
index bc6d0758107922bb46b942b3b52415c3be3633f9..f4b696709acba54d7337b06bd254e1c56b5cbdc1 100644 (file)
@@ -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);
 }
index 39eebe6e46e7fdaaac794f84a8c627a7b22f8b5f..21cd35288181c72786f05172e24650fdcda502f3 100644 (file)
@@ -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 */