summaryrefslogtreecommitdiff
path: root/lib/frrscript.c
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-07-04 22:58:21 +0800
committerDonald Lee <dlqs@gmx.com>2021-07-18 06:32:03 +0800
commit105ba9af8f0bd9a116f2571625b2ea39c49c20c1 (patch)
treec7ae13ddec6cdca02d7d898e84ad39ce14ca186c /lib/frrscript.c
parent432bb280fb4fbe3ce35bd3f2aea3da1ce4e48a03 (diff)
lib: Change frrscript to hold many Lua states
Instead of 1 frrscript : 1 lua state, it is changed to 1 : N. The states are hashed with their function names. Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'lib/frrscript.c')
-rw-r--r--lib/frrscript.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/frrscript.c b/lib/frrscript.c
index 1a9f3639dd..d86e6acb12 100644
--- a/lib/frrscript.c
+++ b/lib/frrscript.c
@@ -102,6 +102,40 @@ static void codec_free(struct codec *c)
}
#endif
+
+unsigned int lua_function_hash_key(const void *data)
+{
+ const struct lua_function_state *lfs = data;
+
+ return string_hash_make(lfs->name);
+}
+
+bool lua_function_hash_cmp(const void *d1, const void *d2)
+{
+ const struct lua_function_state *lfs1 = d1;
+ const struct lua_function_state *lfs2 = d2;
+
+ return strmatch(lfs1->name, lfs2->name);
+}
+
+void *lua_function_alloc(void *arg)
+{
+ struct lua_function_state *tmp = arg;
+
+ struct lua_function_state *lfs =
+ XCALLOC(MTYPE_SCRIPT, sizeof(struct lua_function_state));
+ lfs->name = tmp->name;
+ lfs->L = tmp->L;
+ return lfs;
+}
+
+static void lua_function_free(struct lua_function_state *lfs)
+{
+ XFREE(MTYPE_TMP, lfs->name);
+ lua_close(lfs->L);
+ XFREE(MTYPE_TMP, lfs);
+}
+
/* Generic script APIs */
int _frrscript_call(struct frrscript *fs)