aboutsummaryrefslogtreecommitdiff
path: root/examples/chunk_file_example.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-06-22 19:01:29 +0800
committerDeterminant <[email protected]>2015-06-22 19:01:29 +0800
commit2497fd9e7a0fae5ee4887890d7a312e0e08a93b8 (patch)
tree382f97575bd2df9ee6abb1662b11b279fc22d72b /examples/chunk_file_example.lua
parent196e9b48a3541caccdffc5743001cced70667091 (diff)
major change: use luarocks to manage project
Diffstat (limited to 'examples/chunk_file_example.lua')
-rw-r--r--examples/chunk_file_example.lua53
1 files changed, 0 insertions, 53 deletions
diff --git a/examples/chunk_file_example.lua b/examples/chunk_file_example.lua
deleted file mode 100644
index 5961c98..0000000
--- a/examples/chunk_file_example.lua
+++ /dev/null
@@ -1,53 +0,0 @@
--- To define a readable and writable chunk, one must define a class with the
--- following methods: __init(id, global_conf), read(handle), write(handle),
--- get_info(), set_info(info) and an id attribute. This file demonstrates a
--- basic chunk implementation which manages the I/O of a matrix
-
-local MatrixChunk = nerv.class("nerv.MatrixChunk")
-
-function MatrixChunk:__init(id, global_conf)
- self.id = id
- self.info = {}
- self.gconf = global_conf
-end
-
-function MatrixChunk:read(handle)
- -- pass the read handle to the matrix method
- self.data = nerv.MMatrixFloat.load(handle)
-end
-
-function MatrixChunk:write(handle)
- -- pass the write handle to the matrix method
- self.data:save(handle)
-end
-
-function MatrixChunk:get_info()
- return self.info
-end
-
-function MatrixChunk:set_info(info)
- self.info = info
-end
-
-function MatrixChunk.create_from_matrix(id, mat)
- local ins = nerv.MatrixChunk(id)
- ins.data = mat
- return ins
-end
-
-mat = nerv.MMatrixFloat(3, 4)
-for i = 0, 2 do
- for j = 0, 3 do
- mat[i][j] = i + j
- end
-end
-
-cd = nerv.MatrixChunk.create_from_matrix("matrix1", mat)
-
-cf = nerv.ChunkFile("test.nerv", "w")
-cf:write_chunk(cd)
-cf:close()
-
-cf2 = nerv.ChunkFile("test.nerv", "r")
-cd2 = cf2:read_chunk("matrix1")
-print(cd2.data)