Module: kamailio Branch: 5.4 Commit: afc66f390e135f091dfa7abcc058175817350589 URL: https://github.com/kamailio/kamailio/commit/afc66f390e135f091dfa7abcc0581758...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-07-16T17:31:06+02:00
misc/examples: kemi lua - added debug callback function
- commented - can be enabled to track the execution trace of the lua script
(cherry picked from commit 491a8327933cb4471260fdd09ff93296a7a0ccfd)
---
Modified: misc/examples/kemi/kamailio-basic-kemi-lua.lua
---
Diff: https://github.com/kamailio/kamailio/commit/afc66f390e135f091dfa7abcc0581758... Patch: https://github.com/kamailio/kamailio/commit/afc66f390e135f091dfa7abcc0581758...
---
diff --git a/misc/examples/kemi/kamailio-basic-kemi-lua.lua b/misc/examples/kemi/kamailio-basic-kemi-lua.lua index f5906d0bde..a896529965 100644 --- a/misc/examples/kemi/kamailio-basic-kemi-lua.lua +++ b/misc/examples/kemi/kamailio-basic-kemi-lua.lua @@ -12,6 +12,43 @@ -- the execution of the script. Use KSR.x.exit() after it or KSR.x.drop() --
+-- debug callback function to print details of execution trace +--[[ +local ksr_exec_level=0 + +local function ksr_exec_hook(event) + local s = ""; + local t = debug.getinfo(3) + s = s .. ksr_exec_level .. ">>> " .. string.rep(" ", ksr_exec_level); + if t~=nil and t.currentline>=0 then + s = s .. t.short_src .. ":" .. t.currentline .. " "; + end + t=debug.getinfo(2) + if event=="call" then + ksr_exec_level = ksr_exec_level + 1; + else + ksr_exec_level = ksr_exec_level - 1; + if ksr_exec_level < 0 then + ksr_exec_level = 0; + end + end + if t.what=="main" then + if event=="call" then + s = s .. "begin " .. t.short_src; + else + s = s .. "end " .. t.short_src; + end + elseif t.what=="Lua" then + s = s .. event .. " " .. t.name or "(Lua)" .. " <" .. t.linedefined .. ":" .. t.short_src .. ">"; + else + s = s .. event .. " " .. t.name or "(C)" .. " [" .. t.what .. "] "; + end + KSR.info(s .. "\n"); +end + +debug.sethook(ksr_exec_hook, "cr") +ksr_exec_level=0 +]]--
-- global variables corresponding to defined values (e.g., flags) in kamailio.cfg FLT_ACC=1