aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua125
1 files changed, 0 insertions, 125 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua
deleted file mode 100644
index b5ea985..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/orig-5.1.3/lzio.lua
+++ /dev/null
@@ -1,125 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 lzio.lua
4 Lua 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 position in buffer
21-- z.reader -- chunk reader function
22-- z.data -- additional data
23-- * Current position, p, is now last read index instead of a pointer
24--
25-- Not implemented:
26-- * luaZ_lookahead: used only in lapi.c:lua_load to detect binary chunk
27-- * luaZ_read: used only in lundump.c:ezread to read +1 bytes
28-- * luaZ_openspace: dropped; let Lua handle buffers as strings (used in
29-- lundump.c:LoadString & lvm.c:luaV_concat)
30-- * luaZ buffer macros: dropped; buffers are handled as strings
31-- * lauxlib.c:getF reader implementation has an extraline flag to
32-- skip over a shbang (#!) line, this is not implemented here
33--
34-- Added:
35-- (both of the following are vaguely adapted from lauxlib.c)
36-- * luaZ:make_getS: create Reader from a string
37-- * luaZ:make_getF: create Reader that reads from a file
38--
39-- Changed in 5.1.x:
40-- * Chunkreader renamed to Reader (ditto with Chunkwriter)
41-- * Zio struct: no more name string, added Lua state for reader
42-- (however, Yueliang readers do not require a Lua state)
43----------------------------------------------------------------------]]
44
45luaZ = {}
46
47------------------------------------------------------------------------
48-- * reader() should return a string, or nil if nothing else to parse.
49-- Additional data can be set only during stream initialization
50-- * Readers are handled in lauxlib.c, see luaL_load(file|buffer|string)
51-- * LUAL_BUFFERSIZE=BUFSIZ=512 in make_getF() (located in luaconf.h)
52-- * Original Reader typedef:
53-- const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
54-- * This Lua chunk reader implementation:
55-- returns string or nil, no arguments to function
56------------------------------------------------------------------------
57
58------------------------------------------------------------------------
59-- create a chunk reader from a source string
60------------------------------------------------------------------------
61function luaZ:make_getS(buff)
62 local b = buff
63 return function() -- chunk reader anonymous function here
64 if not b then return nil end
65 local data = b
66 b = nil
67 return data
68 end
69end
70
71------------------------------------------------------------------------
72-- create a chunk reader from a source file
73------------------------------------------------------------------------
74function luaZ:make_getF(filename)
75 local LUAL_BUFFERSIZE = 512
76 local h = io.open(filename, "r")
77 if not h then return nil end
78 return function() -- chunk reader anonymous function here
79 if not h or io.type(h) == "closed file" then return nil end
80 local buff = h:read(LUAL_BUFFERSIZE)
81 if not buff then h:close(); h = nil end
82 return buff
83 end
84end
85
86------------------------------------------------------------------------
87-- creates a zio input stream
88-- returns the ZIO structure, z
89------------------------------------------------------------------------
90function luaZ:init(reader, data)
91 if not reader then return end
92 local z = {}
93 z.reader = reader
94 z.data = data or ""
95 z.name = name
96 -- set up additional data for reading
97 if not data or data == "" then z.n = 0 else z.n = #data end
98 z.p = 0
99 return z
100end
101
102------------------------------------------------------------------------
103-- fill up input buffer
104------------------------------------------------------------------------
105function luaZ:fill(z)
106 local buff = z.reader()
107 z.data = buff
108 if not buff or buff == "" then return "EOZ" end
109 z.n, z.p = #buff - 1, 1
110 return string.sub(buff, 1, 1)
111end
112
113------------------------------------------------------------------------
114-- get next character from the input stream
115-- * local n, p are used to optimize code generation
116------------------------------------------------------------------------
117function luaZ:zgetc(z)
118 local n, p = z.n, z.p + 1
119 if n > 0 then
120 z.n, z.p = n - 1, p
121 return string.sub(z.data, p, p)
122 else
123 return self:fill(z)
124 end
125end