summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@users.noreply.github.com>2021-08-02 13:51:35 +0000
committerGitHub <noreply@github.com>2021-08-02 13:51:35 +0000
commit41d3d77496fb43df16c55c2c5834cdc3048f43d0 (patch)
tree0ee0dcfb67330c179bb27e26eb0dd83d431468c9 /lib/command.c
parent08bbca7511959e1944f0d002dfcc71f51fcb777e (diff)
parentc5f9744c33df5a9d335691d73fbeb1ad8d0e58d4 (diff)
Merge pull request #8982 from dlqs/lua-func-stack
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/command.c b/lib/command.c
index fe17c68a8b..422544b70b 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -2422,28 +2422,30 @@ DEFUN(find,
}
#if defined(DEV_BUILD) && defined(HAVE_SCRIPTING)
-DEFUN(script,
- script_cmd,
- "script SCRIPT",
- "Test command - execute a script\n"
- "Script name (same as filename in /etc/frr/scripts/\n")
+DEFUN(script, script_cmd, "script SCRIPT FUNCTION",
+ "Test command - execute a function in a script\n"
+ "Script name (same as filename in /etc/frr/scripts/)\n"
+ "Function name (in the script)\n")
{
struct prefix p;
(void)str2prefix("1.2.3.4/24", &p);
- struct frrscript *fs = frrscript_load(argv[1]->arg, NULL);
+ struct frrscript *fs = frrscript_new(argv[1]->arg);
- if (fs == NULL) {
- vty_out(vty, "Script '/etc/frr/scripts/%s.lua' not found\n",
- argv[1]->arg);
- } else {
- int ret = frrscript_call(fs, ("p", &p));
- char buf[40];
- prefix2str(&p, buf, sizeof(buf));
- vty_out(vty, "p: %s\n", buf);
- vty_out(vty, "Script result: %d\n", ret);
+ if (frrscript_load(fs, argv[2]->arg, NULL)) {
+ vty_out(vty,
+ "/etc/frr/scripts/%s.lua or function '%s' not found\n",
+ argv[1]->arg, argv[2]->arg);
}
+ int ret = frrscript_call(fs, argv[2]->arg, ("p", &p));
+ char buf[40];
+ prefix2str(&p, buf, sizeof(buf));
+ vty_out(vty, "p: %s\n", buf);
+ vty_out(vty, "Script result: %d\n", ret);
+
+ frrscript_delete(fs);
+
return CMD_SUCCESS;
}
#endif