
SavableTable = public()

function SavableTable:Create()
  if type(self[1]) ~= "string" or self[1] == "" then
    print("error: Savable table must have proper name ")
  else
    CreateSavableArray(self[1])
    self.TabName = self[1]
  end
end

function SavableTable:Destroy()
  DestroySavableArray(self.TabName)
end

function SavableTable:Set(k, v)
  SetSavableArrayValue(self.TabName, k, v) 
end

function SavableTable:Get(k)
  return GetSavableArrayValue(self.TabName, k)
end

function SavableTable:Len()
  return GetSavableArrayIntCount(self.TabName)
end

function SavableTable:Keys()
  return GetSavableArrayKeys(self.TabName)
end

function SavableTable:FullLen()
  return GetSavableArrayIntCount(self.TabName) + GetSavableArrayStrCount(self.TabName)
end

function SavableTable:Pairs()
   local keysStr = GetSavableArrayKeys(self.TabName)
  local keys = keysStr:split(",")
  local i = 0
  local s = 1
  local n = self:Len()
  return function ()
    i = i + 1
    if i <= n then return self:Get(i) 
    elseif s <= #keys then 
      local m = s
      s = s + 1 
      return keys[m],self:Get( keys[m] ) 
    end
  end    
end

function SavableTable:Iterator()
  local i = 0
  local n = self:Len()
  return function ()
    i = i + 1
    if i <= n then return self:Get(i) end
  end  
end

function SavableTable:FullIterator()
  local keysStr = GetSavableArrayKeys(self.TabName)
  local keys = keysStr:split(",")
  local i = 0
  local s = 1
  local n = self:Len()
  return function ()
    i = i + 1
    if i <= n then return self:Get(i) 
    elseif s <= #keys then 
      local m = s
      s = s + 1 
      return self:Get( keys[m] ) 
    end
  end    
end