From f0e78c415e40e28b058b76330fc06af8f1d02c30 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 1 Apr 2013 18:29:12 +0200 Subject: [PATCH] Created init function. Fix clean, just clean its level --- ngcp/xavp.lua | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/ngcp/xavp.lua b/ngcp/xavp.lua index f642597..d5337ea 100644 --- a/ngcp/xavp.lua +++ b/ngcp/xavp.lua @@ -8,23 +8,7 @@ NGCPXAvp_MT = { __index = NGCPXAvp } function NGCPXAvp:new(level,group,l) - if level ~= 'caller' and level ~= 'callee' then - error("unknown level. It has to be [caller|callee]") - end - if not l or #l == 0 then - error("list empty") - end - - local t = { - group = group, - keys = {} - } - if level == 'callee' then - t.level = 1 - else - t.level = 0 - end - NGCPXAvp._create(t, t.level,group,l) + local t = NGCPXAvp.init(level,group,l) NGCPXAvp_MT.__call = function(t, key, value) if not key then error("key is empty") @@ -47,6 +31,28 @@ NGCPXAvp_MT = { return t end + function NGCPXAvp.init(level,group,l) + if level ~= 'caller' and level ~= 'callee' then + error("unknown level. It has to be [caller|callee]") + end + if not l then + error("list empty") + end + + local t = { + group = group, + keys = {} + } + if level == 'callee' then + t.level = 1 + else + t.level = 0 + end + NGCPXAvp._create(t, t.level,group,l) + + return t + end + function NGCPXAvp._setvalue(id, vtype, value) local check = nil -- sr.log("info", string.format("vtype:[%s]:%d", type(vtype), vtype)) @@ -92,10 +98,7 @@ NGCPXAvp_MT = { end function NGCPXAvp:clean() - --print("NGCPXAvp:clean") - --print(table.tostring(getmetatable(self))) - --print(table.tostring(self)) - sr.pv.unset(string.format("$xavp(%s)", self.group)) + sr.pv.unset(string.format("$xavp(%s[%d])", self.group, self.level)) end -- class --EOF \ No newline at end of file