[SR-Users] iterating over htable with lua

David Villasmil david.villasmil.work at gmail.com
Wed May 4 11:36:00 CEST 2022


Hello guys,

I'm trying to iterate over an htable in lus, this is what i have:

===================================
loadmodule "app_lua.so"
modparam("app_lua", "load", "/etc/kamailio/myscript.lua")
modparam("htable", "htable",
"mydata=>size=16;autoexpire=0;dbtable=mydata;dbmode=0;")

route {
    lua_run("match_mydata");
}

...

function match_mydata()
    KSR.htable.sht_iterator_start("i1", "mydata")
    while KSR.htable.sht_iterator_next("i1")
    do
        KSR.log("err","WHILE: iterating on: " .. KSR.htable.sht_get("mydata",
"i1"))
    end
    KSR.htable.sht_iterator_end("i1");
end


But i keep getting:

0(1255) DEBUG: app_lua [app_lua_api.c:666]: app_lua_run_ex(): executing Lua
function: [[match_mydata]]
0(1255) DEBUG: app_lua [app_lua_api.c:668]: app_lua_run_ex(): lua top index
is: 12
0(1255) ERROR: app_lua [app_lua_api.c:719]: app_lua_run_ex(): error from
Lua: /etc/kamailio/myscript.lua:11: attempt to call field
'sht_iterator_start' (a nil value)
0(1255) ERROR: app_lua [app_lua_api.c:734]: app_lua_run_ex(): error
executing: match_mydata (err: 2)

This almost exact same thing works on the cfg:

    sht_iterator_start("i1", "msrn");
    while(sht_iterator_next("i1")) {
        xlog("data: $shtitkey(i1)\n");
    }
    sht_iterator_end("i1");

Anyone know what I could be doing wrong?

Regards,

David Villasmil
email: david.villasmil.work at gmail.com
phone: +34669448337
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20220504/2e28f6ee/attachment.htm>


More information about the sr-users mailing list