[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Copas with 5.1 Final
- From: "Zachary P. Landau" <kapheine@...>
- Date: Tue, 7 Mar 2006 12:43:26 -0500
> Has anyone managed to get Copas running under 5.1 Final? I'm trying
> to get it running now but if someone else has already gone through
> this, I'd appreciate a patch.
>
> So far I had to 'local sym = sym' for globals, since module will cut
> off access to globals now. I also had to replace table.getn/setn with
> an alternate method. This got my farther, but I get a 'copas.lua:172:
> bad argument #1 to 'resume' (coroutine expected). I'll keep plugging
> at this, but I don't want to be repeating work someone else has
> already done.
The attached patch seems to get the job done. The 'bad argument'
error I was getting had to do with me incorrectly passing the handler
function to addserver. It was not an issue with 5.1 final itself.
--
Zachary P. Landau <kapheine@gmail.com>
--- copas-orig.lua 2006-03-07 12:43:47.000000000 -0500
+++ copas.lua 2006-03-07 12:43:56.000000000 -0500
@@ -19,6 +19,16 @@
-------------------------------------------------------------------------------
require "socket"
+local setmetatable = setmetatable
+local table = table
+local coroutine = coroutine
+local math = math
+local error = error
+local next = next
+local socket = socket
+local pairs = pairs
+local string = string
+
module "copas"
-- Meta information is public even begining with an "_"
@@ -36,11 +46,14 @@
setmetatable(set, { __index = {
insert = function(set, value)
table.insert(set, value)
- reverse[value] = table.getn(set)
+ local c = 0
+ for _,_ in pairs(set) do c = c + 1 end
+ reverse[value] = c
end,
remove = function(set, value)
if not reverse[value] then return end
- local last = table.getn(set)
+ local last = 0
+ for _,_ in pairs(set) do last = last + 1 end
if last > 1 then
-- replaces the removed value with the last one
local index = reverse[value]
@@ -48,7 +61,6 @@
set[index] = newvalue
reverse[newvalue] = index
end
- table.setn(set, last - 1)
-- cleans up the garbage
reverse[value] = nil
set[last] = nil