Skip to content

Commit

Permalink
misc/examples: kemi lua - added debug callback function
Browse files Browse the repository at this point in the history
- commented - can be enabled to track the execution trace of the lua
script

(cherry picked from commit 491a832)
  • Loading branch information
miconda authored and henningw committed Oct 2, 2020
1 parent 50ce889 commit c888cc7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions misc/examples/kemi/kamailio-basic-kemi-lua.lua
Expand Up @@ -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
Expand Down

0 comments on commit c888cc7

Please sign in to comment.