summaryrefslogtreecommitdiff
path: root/lib/frrscript.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@nvidia.com>2020-11-29 02:00:26 -0500
committerQuentin Young <qlyoung@nvidia.com>2020-12-01 18:37:14 -0500
commit3b002f19166ca8933c42ebf8f5a7b7794acd53bf (patch)
tree4ab7473da05b47108dd4c9dcf84fe93a621ddb32 /lib/frrscript.h
parent923431ef80fc92b313d812605764b005397fa9bb (diff)
lib: allow passing arguments to scripts
- Add ability to pass arguments when calling a script - Add macros to define arguments and results Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'lib/frrscript.h')
-rw-r--r--lib/frrscript.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/frrscript.h b/lib/frrscript.h
index 6891200def..39eebe6e46 100644
--- a/lib/frrscript.h
+++ b/lib/frrscript.h
@@ -75,9 +75,40 @@ int frrscript_lua_call(struct frrscript *fs, ...);
/*
* Call FRR script.
+ *
+ * Call it like this:
+ *
+ * frrscript_call(fs, FRRSCRIPT_ARGS("cool_prefix", "prefix", p),
+ * FRRSCRIPT_RESULTS("result1", "result2"))
*/
#define frrscript_call(fs, ...) frrscript_lua_call((fs), __VA_ARGS__)
+/*
+ * Macro that defines the arguments to a script.
+ *
+ * For each argument you want to pass to a script, pass *three* arguments to
+ * this function. The first should be name of the variable to bind the argument
+ * to in the script's environment. The second should be the type, as registered
+ * by frrscript_register_type_encoder(). The third should be the argument
+ * itself.
+ *
+ * This macro itself should be used as the second argument to frrscript_call().
+ */
+#define FRRSCRIPT_ARGS(...) PP_NARG(__VA_ARGS__), ##__VA_ARGS__
+
+/*
+ * Macro that defines the results from a script.
+ *
+ * Similar to FRRSCRIPT_ARGS, except this defines the results from a script.
+ *
+ * The first argument should be the name to bind the first result to and will
+ * be used after the script finishes to get that particular result value.
+ *
+ * This macro itself should be used as the third argument to frrscript_call().
+ * It may not be omitted.
+ */
+#define FRRSCRIPT_RESULTS(...) PP_NARG(__VA_ARGS__), ##__VA_ARGS__
+
#ifdef __cplusplus
}
#endif /* __cplusplus */