aboutsummaryrefslogtreecommitdiff
path: root/io/init.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-05-26 14:06:52 +0800
committerDeterminant <[email protected]>2015-05-26 14:06:52 +0800
commit81bf2d653902860c5d28ccade19ac6e1fd56acaf (patch)
tree831a25c84332ac0839dbe498f61620ea634170e0 /io/init.lua
parent8c5246a8794011ca0c25f15643771f031d258594 (diff)
add layer and param
Diffstat (limited to 'io/init.lua')
-rw-r--r--io/init.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/io/init.lua b/io/init.lua
index 1288bd4..2fa38e6 100644
--- a/io/init.lua
+++ b/io/init.lua
@@ -5,3 +5,24 @@ function nerv.ParamFile:write_chunkdata(metadata, writer)
end
return self:_write_chunkdata(table.tostring(metadata), writer)
end
+
+function nerv.ParamFile:write_param(param)
+ local id = param.id
+ local type = param.__typename
+ if id == nil then
+ nerv_error("id of param %s must be specified", type)
+ end
+ self:write_chunkdata({id = id,
+ type = type,
+ info = param:get_info()}, param)
+end
+
+function nerv.ParamFile:read_param(id)
+ local metadata = self.metadata[id]
+ if metadata == nil then
+ nerv_error("param with id %s does not exist", id)
+ end
+ local param = assert(loadstring("return " .. metadata.type .. "(" .. id .. ")"))()
+ param:set_info(metadata.info)
+ param:read(self:get_chunkdata(id))
+end