Debian Codegraph @

misc/tools/kemi/lua/README.md

raw
1 # Tools For KEMI Lua #
2
3 Tools useful for using Kamailio with KEMI Lua scripts.
4
5 ## kemiksrlib.py ##
6
7 Generates the file `KSR.lua` with skeleton functions in the `KSR` object. The
8 function parameters are prefixed with `p_` and the functions return:
9
10 * empty string - in case of functions returning `xval`
11 * `1` - in case of functions returning `int`
12 * `true` - in case of functions returning `int`
13 * nothing - in case of void functions
14 * `nil` - in the other cases
15
16 Useful to use for syntax checking and functions prototypes.
17
18 Usage:
19
20 ```
21 python3 kemiksrlib.py /path/to/src/kamailio
22 ```
23
24 ## kemiluacheck.py ##
25
26 Generates the file `KSR.luacheckrc` that can be used with `luacheck` to verify
27 if the KEMI Lua script uses undefined symbols (e.g., functions that are not
28 in the `KSR` library due to typos).
29
30 Usage:
31
32 ```
33 python3 kemiluacheck.py /path/to/src/kamailio
34
35 luacheck --config KSR.luacheckrc kamailio-basic-kemi-lua.lua -d
36 ```
37
38 Example output with `KSR` correct functions:
39
40 ```
41 Checking kamailio-basic-kemi-lua.lua 5 warnings
42
43 kamailio-basic-kemi-lua.lua:67:10: unused global variable ksr_request_route
44 kamailio-basic-kemi-lua.lua:389:10: unused global variable ksr_branch_manage
45 kamailio-basic-kemi-lua.lua:398:10: unused global variable ksr_onreply_manage
46 kamailio-basic-kemi-lua.lua:409:10: unused global variable ksr_failure_manage
47 kamailio-basic-kemi-lua.lua:420:10: unused global variable ksr_reply_route
48
49 Total: 5 warnings / 0 errors in 1 file
50 ```
51
52 Example output with `KSR.is_CANCLE()` typo:
53
54 ```
55 Checking kamailio-basic-kemi-lua.lua 6 warnings
56
57 kamailio-basic-kemi-lua.lua:67:10: unused global variable ksr_request_route
58 kamailio-basic-kemi-lua.lua:76:5: accessing undefined field is_CANCLE of global KSR
59 kamailio-basic-kemi-lua.lua:389:10: unused global variable ksr_branch_manage
60 kamailio-basic-kemi-lua.lua:398:10: unused global variable ksr_onreply_manage
61 kamailio-basic-kemi-lua.lua:409:10: unused global variable ksr_failure_manage
62 kamailio-basic-kemi-lua.lua:420:10: unused global variable ksr_reply_route
63
64 Total: 6 warnings / 0 errors in 1 file
65 ```
66
67 ## Other Tools ##
68
69 Other external tools useful to check the Lua scripts.
70
71 ### luac ###
72
73 The `luac` (the Lua compiler) can be used with parameter `-p` to check for
74 syntax errors (e.g., missing closing quote or parenthesis).
75
76 Example - when there is a missing closing quote, like:
77
78 ```
79 KSR.hdr.remove("Route);
80 ```
81
82 the check results in:
83
84 ```
85 luac -p kamailio-basic-kemi-lua.lua
86
87 luac: kamailio-basic-kemi-lua.lua:100: unfinished string near '"Route);'
88 ```