This commit is contained in:
Cloud Wu
2015-04-03 11:03:37 +08:00
parent f6118b858d
commit c6f993428e

View File

@@ -30,12 +30,14 @@ function sharemap.writer(typename, obj)
local sp = loadsp() local sp = loadsp()
obj = obj or {} obj = obj or {}
local stmobj = stm.new(sp:encode(typename,obj)) local stmobj = stm.new(sp:encode(typename,obj))
obj.__typename = typename local ret = {
obj.__obj = stmobj __typename = typename,
obj.__data = obj __obj = stmobj,
obj.commit = sharemap.commit __data = obj,
obj.copy = sharemap.copy commit = sharemap.commit,
return setmetatable(obj, { __index = obj.__data, __newindex = obj.__data }) copy = sharemap.copy,
}
return setmetatable(ret, { __index = obj, __newindex = obj })
end end
local function decode(msg, sz, self) local function decode(msg, sz, self)
@@ -63,7 +65,7 @@ function sharemap.reader(typename, stmcpy)
__data = data, __data = data,
update = sharemap.update, update = sharemap.update,
} }
return setmetatable(obj, { __index = obj.__data, __newindex = error }) return setmetatable(obj, { __index = data, __newindex = error })
end end
return sharemap return sharemap