feat(Add dot selectors + count function):

This commit is contained in:
Jérémie N'gadi
2017-10-16 13:13:40 +02:00
parent 3702c8752f
commit 635e18b655
2 changed files with 49 additions and 2 deletions
+48 -2
View File
@@ -1,3 +1,15 @@
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
function CreateDataStore(name, owner, data)
local self = {}
@@ -13,8 +25,42 @@ function CreateDataStore(name, owner, data)
self.save()
end
self.get = function(key)
return data[key]
self.get = function(key, i)
local path = stringsplit(key, '.')
local obj = self.data
for i=1, #path, 1 do
obj = obj[path[i]]
end
if i == nil then
return obj
else
return obj[i]
end
end
self.count = function(key, i)
local path = stringsplit(key, '.')
local obj = self.data
for i=1, #path, 1 do
obj = obj[path[i]]
end
if i ~= nil then
obj = obj[i]
end
if obj == nil then
return 0
else
return #obj
end
end
self.save = function()
+1
View File
@@ -138,3 +138,4 @@ AddEventHandler('esx:playerLoaded', function(source)
xPlayer.set('dataStores', dataStores)
end)