From 2ce634e2ad6cdfddb79e00cda01f21280d521279 Mon Sep 17 00:00:00 2001 From: Donald Lee Date: Sun, 18 Jul 2021 06:25:54 +0800 Subject: [PATCH] lib: formatting Signed-off-by: Donald Lee --- bgpd/bgp_routemap.c | 3 ++- lib/frrscript.c | 7 +++--- lib/frrscript.h | 59 +++++++++++++++++++++++---------------------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 9146e90fbf..5bdc37c9ad 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -396,7 +396,8 @@ route_match_script(void *rule, const struct prefix *prefix, void *object) return RMAP_NOMATCH; } - long long* action = frrscript_get_result(fs, routematch_function, "action", lua_tointegerp); + long long *action = frrscript_get_result(fs, routematch_function, + "action", lua_tointegerp); int status = RMAP_NOMATCH; diff --git a/lib/frrscript.c b/lib/frrscript.c index b3f8a9f6f5..b385ad7eaa 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -205,12 +205,12 @@ void *frrscript_get_result(struct frrscript *fs, const char *function_name, lfs = hash_lookup(fs->lua_function_hash, &lookup); - if (lfs == NULL) { + if (lfs == NULL) return NULL; - } /* results table is idx 1 on the stack, getfield pushes our item to idx - * 2*/ + * 2 + */ lua_getfield(lfs->L, 1, name); if (lua_isnil(lfs->L, -1)) { lua_pop(lfs->L, 1); @@ -259,6 +259,7 @@ int frrscript_load(struct frrscript *fs, const char *function_name, /* Set up the Lua script */ lua_State *L = luaL_newstate(); + frrlua_export_logging(L); char script_name[MAXPATHLEN * 2]; diff --git a/lib/frrscript.h b/lib/frrscript.h index d756b49533..e76d14c1f4 100644 --- a/lib/frrscript.h +++ b/lib/frrscript.h @@ -146,7 +146,7 @@ void frrscript_init(const char *scriptdir); */ #define ENCODE_ARGS_WITH_STATE(L, value) \ _Generic((value), \ -int: lua_pushinteger, \ +int : lua_pushinteger, \ long long * : lua_pushintegerp, \ struct prefix * : lua_pushprefix, \ struct interface * : lua_pushinterface, \ @@ -180,9 +180,8 @@ const struct prefix * : lua_decode_noop \ * Call Lua function state (abstraction for a single Lua function) * * lfs - * The Lua function to call; this should have been loaded in by frrscript_load(). - * nargs - * Number of arguments the function accepts + * The Lua function to call; this should have been loaded in by + * frrscript_load(). nargs Number of arguments the function accepts * * Returns: * 0 if the script ran successfully, nonzero otherwise. @@ -201,31 +200,33 @@ int _frrscript_call_lua(struct lua_function_state *lfs, int nargs); * Returns: * 0 if the script ran successfully, nonzero otherwise. */ -#define frrscript_call(fs, f, ...) \ - ({ \ - struct lua_function_state lookup = {.name = f}; \ - struct lua_function_state *lfs; \ - lfs = hash_lookup(fs->lua_function_hash, &lookup); \ - lfs == NULL ? ({ \ - zlog_err( \ - "frrscript: '%s.lua': '%s': tried to call this function but it was not loaded", \ - fs->name, f); \ - 1; \ - }) \ - : ({ \ - MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__); \ - _frrscript_call_lua(lfs, PP_NARG(__VA_ARGS__)); \ - }) != 0 \ - ? ({ \ - zlog_err( \ - "frrscript: '%s.lua': '%s': this function called but returned non-zero exit code. No variables modified.", \ - fs->name, f); \ - 1; \ - }) \ - : ({ \ - MAP_LISTS(DECODE_ARGS, ##__VA_ARGS__); \ - 0; \ - }); \ +#define frrscript_call(fs, f, ...) \ + ({ \ + struct lua_function_state lookup = {.name = f}; \ + struct lua_function_state *lfs; \ + lfs = hash_lookup(fs->lua_function_hash, &lookup); \ + lfs == NULL ? ({ \ + zlog_err( \ + "frrscript: '%s.lua': '%s': tried to call this function but it was not loaded", \ + fs->name, f); \ + 1; \ + }) \ + : ({ \ + MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__); \ + _frrscript_call_lua( \ + lfs, PP_NARG(__VA_ARGS__)); \ + }) != 0 \ + ? ({ \ + zlog_err( \ + "frrscript: '%s.lua': '%s': this function called but returned non-zero exit code. No variables modified.", \ + fs->name, f); \ + 1; \ + }) \ + : ({ \ + MAP_LISTS(DECODE_ARGS, \ + ##__VA_ARGS__); \ + 0; \ + }); \ }) /* -- 2.39.5