diff options
| author | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
| commit | 920bc9762954454468d056a61391635cbd849406 (patch) | |
| tree | 048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/ltn12.lua | |
| parent | bd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff) | |
| download | luasocket-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.lua | 26 |
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 @@ | |||
| 10 | local string = require("string") | 10 | local string = require("string") |
| 11 | local table = require("table") | 11 | local table = require("table") |
| 12 | local base = _G | 12 | local base = _G |
| 13 | module("ltn12") | 13 | ltn12 = {} |
| 14 | local _M = ltn12 | ||
| 14 | 15 | ||
| 15 | filter = {} | 16 | local filter,source,sink,pump = {},{},{},{} |
| 16 | source = {} | 17 | |
| 17 | sink = {} | 18 | _M.filter = filter |
| 18 | pump = {} | 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... |
| 21 | BLOCKSIZE = 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) |
| 39 | function filter.chain(...) | 42 | function 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 | |||
| 89 | function source.file(handle, io_err) | 92 | function 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 |
| 292 | end | 295 | end |
| 293 | 296 | ||
| 297 | return _M \ No newline at end of file | ||
