summaryrefslogtreecommitdiff
path: root/lib/frrscript.h
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-06-20 08:25:22 +0800
committerDonald Lee <dlqs@gmx.com>2021-06-22 05:02:03 +0800
commit3a3cfe4762753dbd5744acaa02153c49f6c73fe1 (patch)
tree53a29163daef84516c7568a4e311834be4926fc6 /lib/frrscript.h
parentc2642aab24cdbfc7a0b0b203aca9835d52d938ef (diff)
lib: Add decoder functions
Split existing lua_to* functions into two functions: - lua_decode_*: unmarshall Lua values into an existing C data structure - lua_to*: allocate *and* unmarshall Lua values into C data structure This allows us to mutate C data structures passed into frrscript_call, without allocation Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'lib/frrscript.h')
-rw-r--r--lib/frrscript.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/frrscript.h b/lib/frrscript.h
index 5410f53e11..14e1834a11 100644
--- a/lib/frrscript.h
+++ b/lib/frrscript.h
@@ -105,7 +105,7 @@ void frrscript_init(const char *scriptdir);
#define DECODE_ARGS(name, value) \
do { \
lua_getglobal(L, name); \
- DECODE_ARGS_WITH_STATE(L, value) \
+ DECODE_ARGS_WITH_STATE(L, value); \
} while (0)
#define ENCODE_ARGS_WITH_STATE(L, value) \
@@ -120,7 +120,17 @@ time_t * : lua_pushtimet, \
char * : lua_pushstring_wrapper \
)(L, value)
-#define DECODE_ARGS_WITH_STATE(L, value) _Generic((value), )(L, value);
+#define DECODE_ARGS_WITH_STATE(L, value) \
+ _Generic((value), \
+long long * : lua_decode_integerp, \
+struct prefix * : lua_decode_prefix, \
+struct interface * : lua_decode_interface, \
+struct in_addr * : lua_decode_inaddr, \
+struct in6_addr * : lua_decode_in6addr, \
+union sockunion * : lua_decode_sockunion, \
+time_t * : lua_decode_timet, \
+char * : lua_decode_stringp \
+)(L, -1, value)
/*
* Call script.