aboutsummaryrefslogtreecommitdiff
path: root/src/ltn12.lua
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
committermoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
commit920bc9762954454468d056a61391635cbd849406 (patch)
tree048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/ltn12.lua
parentbd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff)
downloadluasocket-920bc9762954454468d056a61391635cbd849406.tar.gz
luasocket-920bc9762954454468d056a61391635cbd849406.tar.bz2
luasocket-920bc9762954454468d056a61391635cbd849406.zip
Build with Lua 5.2 without LUA_COMPAT_MODULE flag.
LUASOCKET_USE_GLOBAL flag enable create global variables when load socket/mime modules.
Diffstat (limited to 'src/ltn12.lua')
-rw-r--r--src/ltn12.lua26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua
index fca1cb2..c5f7c4c 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -10,16 +10,19 @@
10local string = require("string") 10local string = require("string")
11local table = require("table") 11local table = require("table")
12local base = _G 12local base = _G
13module("ltn12") 13ltn12 = {}
14local _M = ltn12
14 15
15filter = {} 16local filter,source,sink,pump = {},{},{},{}
16source = {} 17
17sink = {} 18_M.filter = filter
18pump = {} 19_M.source = source
20_M.sink = sink
21_M.pump = pump
19 22
20-- 2048 seems to be better in windows... 23-- 2048 seems to be better in windows...
21BLOCKSIZE = 2048 24_M.BLOCKSIZE = 2048
22_VERSION = "LTN12 1.0.2" 25_M._VERSION = "LTN12 1.0.2"
23 26
24----------------------------------------------------------------------------- 27-----------------------------------------------------------------------------
25-- Filter stuff 28-- Filter stuff
@@ -38,7 +41,7 @@ end
38-- (thanks to Wim Couwenberg) 41-- (thanks to Wim Couwenberg)
39function filter.chain(...) 42function filter.chain(...)
40 local arg = {...} 43 local arg = {...}
41 local n = #arg 44 local n = select('#',...)
42 local top, index = 1, 1 45 local top, index = 1, 1
43 local retry = "" 46 local retry = ""
44 return function(chunk) 47 return function(chunk)
@@ -89,7 +92,7 @@ end
89function source.file(handle, io_err) 92function source.file(handle, io_err)
90 if handle then 93 if handle then
91 return function() 94 return function()
92 local chunk = handle:read(BLOCKSIZE) 95 local chunk = handle:read(_M.BLOCKSIZE)
93 if not chunk then handle:close() end 96 if not chunk then handle:close() end
94 return chunk 97 return chunk
95 end 98 end
@@ -112,8 +115,8 @@ function source.string(s)
112 if s then 115 if s then
113 local i = 1 116 local i = 1
114 return function() 117 return function()
115 local chunk = string.sub(s, i, i+BLOCKSIZE-1) 118 local chunk = string.sub(s, i, i+_M.BLOCKSIZE-1)
116 i = i + BLOCKSIZE 119 i = i + _M.BLOCKSIZE
117 if chunk ~= "" then return chunk 120 if chunk ~= "" then return chunk
118 else return nil end 121 else return nil end
119 end 122 end
@@ -291,3 +294,4 @@ function pump.all(src, snk, step)
291 end 294 end
292end 295end
293 296
297return _M \ No newline at end of file