Open
Conversation
测试完成,问题是b遍历经过赋值table后,被清空了
个人觉得107行应该改成
local keys = {}
for k in pairs(lv._lastversion) do --加上._lastversion
keys[k] = true
end
Owner
local tracedoc = require "tracedoc"
local doc = tracedoc.new {
a = 1,
b = { 1,2,3 },
c = { d = 4 , e = 5 },
d = {},
}
doc.b[3] = nil
doc.b = { 1,3 } -- remove [3], change [2]
tracedoc.commit(doc, {})
assert(doc.b[1] == 1)
assert(doc.b[2] == 3)
for k,v in pairs(doc.b) do
print(k,v)
end
-- 1 1
-- 2 3这里 doc.b 是正常的。 |
Author
|
local tracedoc = require "tracedoc" local doc = tracedoc.new { -- 改变值 -- 提交 -- 再改变值 assert(doc.b[1] == 1) for k,v in pairs(doc.b) do 这样就出问题了 |
Owner
|
上面代码输出为 正常啊 ps. 请学习一下 markdown 语法,正确贴代码。 |
Author
local tracedoc = require "app.tracedoc"
local doc = tracedoc.new {
a = 1,
b = { 1,2,3 },
c = { d = 4 , e = 5 },
d = {},
}
print("-----------------------------------")
-- 改变值
doc.b[3] = nil
-- 提交
tracedoc.commit(doc, {})
-- 再改变值
doc.b = { 1,3 } -- remove [3], change [2]
assert(doc.b[1] == 1)
assert(doc.b[2] == 3)
for k,v in pairs(doc.b) do
print(k,v)
end
print("no message")结果就这样了 |
Owner
|
只支持 lua 5.3 , 如果使用低版本 lua ,需要自己实现 pairs 方法,支持 |
Author
|
好的,谢谢了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
测试完成,问题是b遍历经过赋值table后,被清空了
个人觉得107行应该改成
local keys = {}
for k in pairs(lv._lastversion) do --加上._lastversion
keys[k] = true
end