Shared Table
*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处。
摘要
职能
clear(st: SharedTable):() |
clone(st: SharedTable,deep: boolean?):SharedTable |
cloneAndFreeze(st: SharedTable,deep: boolean?):SharedTable |
isFrozen(st: SharedTable):boolean |
size(st: SharedTable):number |
update(st: SharedTable,key: string | number,f: function):() |
代码示例
元素访问
local st = SharedTable.new()
st[1] = "a"
st["x"] = true
st.y = 5
assert(st[1] == "a")
assert(st["x"] == true)
assert(st.x == true)
assert(st["y"] == 5)
assert(st.y == 5)
-- true 不是一个有效的 SharedTable 键,因此尝试设置该键
-- 会失败:
assert(not pcall(function() st[true] = 100 end))
-- 函数不是一个有效的 SharedTable 值,因此尝试将值设置为函数
-- 会失败:
assert(not pcall(function() st["f"] = function() end end))元素迭代
local st = SharedTable.new({"a", "b", "c"})
for k, v in SharedTable.clone(st, false) do
print(k, ": ", v)
end
for k, v in st do
print(k, ": ", v)
endAPI 参考
构造工具
new
Shared Table. new()
职能
clone
参数
| 默认值:false |
clone And Freeze
参数
| 默认值:false |
increment
参数
返回
update
参数
返回
()