Copas with 5.1 Final

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Copas with 5.1 Final

Zachary P. Landau-4
Hello,

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.

--
Zachary P. Landau <[hidden email]>


Reply | Threaded
Open this post in threaded view
|

Re: Copas with 5.1 Final

Zachary P. Landau-4
> 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 <[hidden email]>
--- 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
Reply | Threaded
Open this post in threaded view
|

RE: Copas with 5.1 Final

Andre Carregal
In reply to this post by Zachary P. Landau-4
> [[hidden email] Behalf Of Zachary P. Landau
> 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.

Thanks for the patch Zachary.

We are still working on the Compat R5 version of Kepler modules, but the
next step will be the migration to Lua 5.1 and your help is welcome.

By the way, feel free to use the Kepler mailing list for issues like that.
http://luaforge.net/mail/?group_id=104

André


Reply | Threaded
Open this post in threaded view
|

Re: Copas with 5.1 Final

Chris Lajoie
> By the way, feel free to use the Kepler mailing list for issues like that.
> http://luaforge.net/mail/?group_id=104

Somehow I missed the original post regarding this. I've been wanting a
Kepler list for a while.

Chris