summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua')
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua42
1 files changed, 24 insertions, 18 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
index cc8cb23c882..24854155408 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
@@ -5,6 +5,7 @@
-----------------------------------------------------------------------------
local base = _G
local table = require("table")
+local string = require("string")
local socket = require("socket")
local coroutine = require("coroutine")
module("dispatch")
@@ -43,26 +44,32 @@ end
-----------------------------------------------------------------------------
-- Mega hack. Don't try to do this at home.
-----------------------------------------------------------------------------
--- we can't yield across calls to protect, so we rewrite it with coxpcall
+-- we can't yield across calls to protect on Lua 5.1, so we rewrite it with
+-- coroutines
-- make sure you don't require any module that uses socket.protect before
-- loading our hack
-function socket.protect(f)
- return function(...)
- local co = coroutine.create(f)
- while true do
- local results = {coroutine.resume(co, base.unpack(arg))}
- local status = table.remove(results, 1)
- if not status then
- if base.type(results[1]) == 'table' then
- return nil, results[1][1]
- else base.error(results[1]) end
- end
- if coroutine.status(co) == "suspended" then
- arg = {coroutine.yield(base.unpack(results))}
+if string.sub(base._VERSION, -3) == "5.1" then
+ local function _protect(co, status, ...)
+ if not status then
+ local msg = ...
+ if base.type(msg) == 'table' then
+ return nil, msg[1]
else
- return base.unpack(results)
+ base.error(msg, 0)
end
end
+ if coroutine.status(co) == "suspended" then
+ return _protect(co, coroutine.resume(co, coroutine.yield(...)))
+ else
+ return ...
+ end
+ end
+
+ function socket.protect(f)
+ return function(...)
+ local co = coroutine.create(f)
+ return _protect(co, coroutine.resume(co, ...))
+ end
end
end
@@ -76,7 +83,7 @@ local function newset()
insert = function(set, value)
if not reverse[value] then
table.insert(set, value)
- reverse[value] = table.getn(set)
+ reverse[value] = #set
end
end,
remove = function(set, value)
@@ -104,8 +111,7 @@ local function cowrap(dispatcher, tcp, error)
-- don't override explicitly.
local metat = { __index = function(table, key)
table[key] = function(...)
- arg[1] = tcp
- return tcp[key](base.unpack(arg))
+ return tcp[key](tcp,select(2,...))
end
return table[key]
end}