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>
This commit is contained in:
Quentin Young 2020-11-29 14:51:52 -05:00
parent 224782816d
commit 9e47ee98a3
5 changed files with 13 additions and 28 deletions

View File

@ -394,7 +394,7 @@ route_match_command(void *rule, const struct prefix *prefix, void *object)
/* /*
* Setup the prefix information to pass in * Setup the prefix information to pass in
*/ */
frrlua_newtable_prefix(L, prefix); lua_pushprefix(L, prefix);
/* /*
* Setup the bgp_path_info information * Setup the bgp_path_info information
*/ */

View File

@ -37,19 +37,6 @@
* stack easier. * 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 frrlua_table_get_integer(lua_State *L, const char *key)
{ {
int result; int result;
@ -70,7 +57,7 @@ int frrlua_table_get_integer(lua_State *L, const char *key)
* datatypes. * 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]; char buffer[100];
@ -87,7 +74,7 @@ int frrlua_newtable_prefix(lua_State *L, const struct prefix *prefix)
return 0; 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"); zlog_debug("frrlua: pushing interface table");

View File

@ -21,9 +21,9 @@
#if defined(HAVE_LUA) #if defined(HAVE_LUA)
#include "lua.h" #include <lua.h>
#include "lualib.h" #include <lualib.h>
#include "lauxlib.h" #include <lauxlib.h>
#include "prefix.h" #include "prefix.h"
#include "frrscript.h" #include "frrscript.h"
@ -34,15 +34,13 @@ extern "C" {
/* /*
* Pushes a new table containing relevant fields from a prefix structure. * 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. * 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. * Retrieve a string from table on the top of the stack.

View File

@ -220,8 +220,7 @@ void frrscript_init()
"Lua type encoders"); "Lua type encoders");
/* Register core library types */ /* Register core library types */
frrscript_register_type_encoder("prefix", frrscript_register_type_encoder("prefix", (encoder_func)lua_pushprefix);
(encoder_func)frrlua_newtable_prefix); frrscript_register_type_encoder("interface",
frrscript_register_type_encoder( (encoder_func)lua_pushinterface);
"interface", (encoder_func)frrlua_newtable_interface);
} }

View File

@ -19,6 +19,7 @@
#ifndef __FRRSCRIPT_H__ #ifndef __FRRSCRIPT_H__
#define __FRRSCRIPT_H__ #define __FRRSCRIPT_H__
#include <lua.h>
#include "frrlua.h" #include "frrlua.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -27,7 +28,7 @@ extern "C" {
#define FRRSCRIPT_PATH "/etc/frr/scripts" #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 { struct frrscript {
/* Script name */ /* Script name */