aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua120
1 files changed, 0 insertions, 120 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua
deleted file mode 100644
index 7b98246..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/lzio.lua
+++ /dev/null
@@ -1,120 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 lzio.lua
4 Lua 5 buffered streams in Lua
5 This file is part of Yueliang.
6
7 Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15--[[--------------------------------------------------------------------
16-- Notes:
17-- * EOZ is implemented as a string, "EOZ"
18-- * Format of z structure (ZIO)
19-- z.n -- bytes still unread
20-- z.p -- last read position in buffer
21-- z.reader -- chunk reader function
22-- z.data -- additional data
23-- z.name -- name of stream
24-- * Current position, p, is now last read index instead of a pointer
25--
26-- Not implemented:
27-- * luaZ_lookahead: used only in lapi.c:lua_load to detect binary chunk
28-- * luaZ_read: used only in lundump.c:ezread to read +1 bytes
29-- * luaZ_openspace: dropped; let Lua handle buffers as strings
30-- * luaZ buffer macros: dropped; unused for now
31--
32-- Alternatives:
33-- * zname(z) is z.name
34--
35-- Added:
36-- (both of the following are vaguely adapted from lauxlib.c)
37-- * luaZ:make_getS: create Chunkreader from a string
38-- * luaZ:make_getF: create Chunkreader that reads from a file
39----------------------------------------------------------------------]]
40
41luaZ = {}
42
43------------------------------------------------------------------------
44-- * reader() should return a string, or nil if nothing else to parse.
45-- Unlike Chunkreaders, there are no arguments like additional data
46-- * Chunkreaders are handled in lauxlib.h, see luaL_load(file|buffer)
47-- * Original Chunkreader:
48-- const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t *sz);
49-- * This Lua chunk reader implementation:
50-- returns string or nil, no arguments to function
51------------------------------------------------------------------------
52
53------------------------------------------------------------------------
54-- create a chunk reader from a source string
55------------------------------------------------------------------------
56function luaZ:make_getS(buff)
57 local b = buff
58 return function() -- chunk reader anonymous function here
59 if not b then return nil end
60 local data = b
61 b = nil
62 return data
63 end
64end
65
66------------------------------------------------------------------------
67-- create a chunk reader from a source file
68------------------------------------------------------------------------
69function luaZ:make_getF(filename)
70 local LUAL_BUFFERSIZE = 512
71 local h = io.open(filename, "r")
72 if not h then return nil end
73 return function() -- chunk reader anonymous function here
74 if not h or io.type(h) == "closed file" then return nil end
75 local buff = h:read(LUAL_BUFFERSIZE)
76 if not buff then h:close(); h = nil end
77 return buff
78 end
79end
80
81------------------------------------------------------------------------
82-- creates a zio input stream
83-- returns the ZIO structure, z
84------------------------------------------------------------------------
85function luaZ:init(reader, data, name)
86 if not reader then return end
87 local z = {}
88 z.reader = reader
89 z.data = data or ""
90 z.name = name
91 -- set up additional data for reading
92 if not data or data == "" then z.n = 0 else z.n = string.len(data) end
93 z.p = 0
94 return z
95end
96
97------------------------------------------------------------------------
98-- fill up input buffer
99------------------------------------------------------------------------
100function luaZ:fill(z)
101 local data = z.reader()
102 z.data = data
103 if not data or data == "" then return "EOZ" end
104 z.n = string.len(data) - 1
105 z.p = 1
106 return string.sub(data, 1, 1)
107end
108
109------------------------------------------------------------------------
110-- get next character from the input stream
111------------------------------------------------------------------------
112function luaZ:zgetc(z)
113 if z.n > 0 then
114 z.n = z.n - 1
115 z.p = z.p + 1
116 return string.sub(z.data, z.p, z.p)
117 else
118 return self:fill(z)
119 end
120end