summaryrefslogtreecommitdiff
path: root/lib/frrscript.h
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-06-14 14:54:58 +0800
committerDonald Lee <dlqs@gmx.com>2021-06-22 04:51:22 +0800
commit43a5106d42b6054ca1dbdee7d455a5212c3094ca (patch)
tree6ce00b0d13c73aeead3db705b45821e8eb8afc1b /lib/frrscript.h
parent249cd5daa70e32163fda202d27cfe5839eee0e6d (diff)
lib: make frrscript_call encode args based on type
Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'lib/frrscript.h')
-rw-r--r--lib/frrscript.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/frrscript.h b/lib/frrscript.h
index f4057f531b..06d247f38d 100644
--- a/lib/frrscript.h
+++ b/lib/frrscript.h
@@ -96,6 +96,21 @@ void frrscript_register_type_codecs(struct frrscript_codec *codecs);
*/
void frrscript_init(const char *scriptdir);
+#define ENCODE_ARGS(name, value) \
+ do { \
+ ENCODE_ARGS_WITH_STATE(L, value) \
+ lua_setglobal(L, name); \
+ } while (0)
+
+#define DECODE_ARGS(name, value) \
+ do { \
+ lua_getglobal(L, name); \
+ DECODE_ARGS_WITH_STATE(L, value) \
+ } while (0)
+
+#define ENCODE_ARGS_WITH_STATE(L, value) _Generic((value), )(L, value);
+
+#define DECODE_ARGS_WITH_STATE(L, value) _Generic((value), )(L, value);
/*
* Call script.
@@ -109,8 +124,18 @@ void frrscript_init(const char *scriptdir);
* Returns:
* 0 if the script ran successfully, nonzero otherwise.
*/
-int frrscript_call(struct frrscript *fs, struct frrscript_env *env);
-
+int _frrscript_call(struct frrscript *fs);
+
+#define frrscript_call(fs, ...) \
+ ({ \
+ lua_State *L = fs->L; \
+ MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__); \
+ int ret = _frrscript_call(fs); \
+ if (ret == 0) { \
+ MAP_LISTS(DECODE_ARGS, ##__VA_ARGS__); \
+ } \
+ ret; \
+ })
/*
* Get result from finished script.