Module: kamailio
Branch: master
Commit: 8bce8a738e16303985ed386213e1d86a1a6a7878
URL:
https://github.com/kamailio/kamailio/commit/8bce8a738e16303985ed386213e1d86…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-12-09T20:15:31+01:00
misc: kemi-code-gen.py - generate code for lua functions with 3 params and xval return
---
Modified: misc/tools/kemi/kemi-code-gen.py
---
Diff:
https://github.com/kamailio/kamailio/commit/8bce8a738e16303985ed386213e1d86…
Patch:
https://github.com/kamailio/kamailio/commit/8bce8a738e16303985ed386213e1d86…
---
diff --git a/misc/tools/kemi/kemi-code-gen.py b/misc/tools/kemi/kemi-code-gen.py
index 8593c154140..6c2893a6884 100644
--- a/misc/tools/kemi/kemi-code-gen.py
+++ b/misc/tools/kemi/kemi-code-gen.py
@@ -2,9 +2,9 @@
# - print IF conditions with param types for KEMI interpreters
# - print typedefs for functions
-PRINTPARAMS=4
+PRINTPARAMS=3
# - print mode: typedefs, js, lua, python, pythonparams, ruby, sqlang
-PRINTMODE="sqlang"
+PRINTMODE="lua"
# - two tabs for python params, three for the other cases
# PRINTTABS="\t\t"
PRINTTABS="\t\t\t"
@@ -62,33 +62,42 @@ def printCodeIfJS(prefix):
def printCodeIfLua(prefix):
global PRINTELSE
- sfunc = PRINTTABS + "\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(env_L->msg,\n" + PRINTTABS + "\t\t\t"
+ sparams = ""
for i, c in enumerate(prefix):
if i==0:
if c == 's':
print(PRINTTABS + PRINTELSE + "if(ket->ptypes[0]==SR_KEMIP_STR")
- sfunc += "&vps[" + str(i) +"].s, "
+ sparams += "&vps[" + str(i) +"].s, "
else:
print(PRINTTABS + PRINTELSE + "if(ket->ptypes[0]==SR_KEMIP_INT")
- sfunc += "vps[" + str(i) +"].n, "
+ sparams += "vps[" + str(i) +"].n, "
PRINTELSE = "} else "
elif i==PRINTPARAMS-1:
if c == 's':
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_STR) {")
- sfunc += "&vps[" + str(i) +"].s);"
+ sparams += "&vps[" + str(i) +"].s);"
else:
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_INT) {")
- sfunc += "vps[" + str(i) +"].n);"
+ sparams += "vps[" + str(i) +"].n);"
else:
if c == 's':
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_STR")
- sfunc += "&vps[" + str(i) +"].s, "
+ sparams += "&vps[" + str(i) +"].s, "
else:
print(PRINTTABS + "\t\t&& ket->ptypes[" + str(i) +
"]==SR_KEMIP_INT")
- sfunc += "vps[" + str(i) +"].n, "
+ sparams += "vps[" + str(i) +"].n, "
- print(sfunc)
- print(PRINTTABS + "\treturn sr_kemi_lua_return_int(L, ket, ret);")
+ print("\t\t\t\tif(ket->rtype==SR_KEMIP_XVAL) {")
+ sfunc = PRINTTABS + "\t\txret = ((sr_kemi_xfm" + prefix +
"_f)(ket->func))(env_L->msg,\n" + PRINTTABS + "\t\t\t"
+ print(sfunc + sparams)
+ print(PRINTTABS + "\t\treturn sr_kemi_lua_return_xval(L, ket, xret);")
+
+ print("\t\t\t\t} else {")
+ sfunc = PRINTTABS + "\t\tret = ((sr_kemi_fm" + prefix +
"_f)(ket->func))(env_L->msg,\n" + PRINTTABS + "\t\t\t"
+
+ print(sfunc + sparams)
+ print(PRINTTABS + "\t\treturn sr_kemi_lua_return_int(L, ket, ret);")
+ print("\t\t\t\t}")
def printCodeIfPython(prefix):