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);
/* Set up the Lua script */
lua_State *L = luaL_newstate();
+
frrlua_export_logging(L);
char script_name[MAXPATHLEN * 2];
*/
#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, \
* 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.
* 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; \
+ }); \
})
/*