mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-26 00:53:44 +01:00
Optional parameters to Store() addded
This commit is contained in:
parent
9642fd3b04
commit
12798bb7d2
@ -35,13 +35,13 @@ safer_lua.DataStructHelp = [[
|
||||
Unlike arrays, which are indexed by a range of numbers,
|
||||
'stores' are indexed by keys:
|
||||
|
||||
s = Store() --> {}
|
||||
s.set("val", 12) --> {val = 12}
|
||||
s = Store("a",4,"b",5) --> {a = 4, b = 5}
|
||||
s.set("val", 12) --> {a = 4, b = 5, val = 12}
|
||||
s.get("val") --> returns 12
|
||||
s.set(0, "hello") --> {val = 12, [0] = "hello"}
|
||||
s.set(0, "hello") --> {a = 4, b = 5, val = 12, [0] = "hello"}
|
||||
s.del("val") --> {[0] = "hello"}
|
||||
s.size() --> function returns 1
|
||||
s.memsize() --> function returns 6
|
||||
s.size() --> function returns 4
|
||||
s.memsize() --> function returns 8
|
||||
s.next() --> for loop iterator function
|
||||
s.keys(order) --> return an array with the keys
|
||||
|
||||
@ -76,7 +76,7 @@ local function var_count(v)
|
||||
end
|
||||
|
||||
|
||||
function safer_lua.Store()
|
||||
function safer_lua.Store(...)
|
||||
|
||||
local new_t = {}
|
||||
local mt = {}
|
||||
@ -171,6 +171,11 @@ function safer_lua.Store()
|
||||
Data = data
|
||||
end
|
||||
|
||||
for idx = 1,select('#',...),2 do
|
||||
local k,v = select(idx,...),select(idx+1,...)
|
||||
new_t.set(k,v)
|
||||
end
|
||||
|
||||
return setmetatable(new_t, mt)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user