lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I hit a few minor issues when trying to build the lposix library for
lua 5.1 -- I've attached a patch that addresses these:
- the change posted at
http://lua-users.org/lists/lua-l/2007-05/msg00087.html
- a problem with CLK_TCK not being defined.  I just renamed this to
CLOCKS_PER_SEC, which, I believe, has superceded CLK_TCK.
- changes to lua code for 5.1 compliance

I'm posting here in case others want to use this, or incorporate back into lposix itself.

James

diff -ur posix-old/lposix.c posix/lposix.c
--- posix-old/lposix.c	2003-11-06 00:23:48.000000000 +0000
+++ posix/lposix.c	2007-10-16 16:24:50.000000000 +0100
@@ -64,8 +64,7 @@
 	}
 	else
 	{
-		int j=luaL_findstring(luaL_checkstring(L, i), S);
-		if (j==-1) luaL_argerror(L, i, "unknown selector");
+		int j=luaL_checkoption(L, i, NULL, S);
 		return F(L, j, data);
 	}
 }
@@ -599,7 +598,7 @@
  clock_t elapsed;
 };
 
-#define pushtime(L,x)		lua_pushnumber(L,((lua_Number)x)/CLK_TCK)
+#define pushtime(L,x)		lua_pushnumber(L,((lua_Number)x)/CLOCKS_PER_SEC)
 
 static int Ftimes(lua_State *L, int i, const void *data)
 {
diff -ur posix-old/posix.lua posix/posix.lua
--- posix-old/posix.lua	2003-06-18 13:47:44.000000000 +0100
+++ posix/posix.lua	2007-10-16 16:32:30.000000000 +0100
@@ -4,7 +4,7 @@
 
 local function so(x)
 	local SOPATH= os.getenv"LUA_SOPATH" or "./"
-	assert(loadlib(SOPATH.."l"..x..".so","luaopen_"..x))()
+	assert(package.loadlib(SOPATH.."l"..x..".so","luaopen_"..x))()
 end
 
 so"posix"
diff -ur posix-old/test.lua posix/test.lua
--- posix-old/test.lua	2003-11-07 11:42:30.000000000 +0000
+++ posix/test.lua	2007-10-16 16:43:19.000000000 +0100
@@ -41,7 +41,7 @@
 f"HOME"
 f"SHELL"
 f"absent"
-for k in ox.getenv() do io.write(k,"\t") end io.write"\n"
+for k in pairs(ox.getenv()) do io.write(k,"\t") end io.write"\n"
 
 ------------------------------------------------------------------------------
 testing"putenv"
@@ -179,11 +179,11 @@
 ------------------------------------------------------------------------------
 testing"times"
 a=ox.times()
-for k,v in a do print(k,v) end
+for k,v in pairs(a) do print(k,v) end
 print"sleeping 10 seconds..."
 ox.sleep(10)
 b=ox.times()
-for k,v in b do print(k,v) end
+for k,v in pairs(b) do print(k,v) end
 print""
 print("elapsed",b.elapsed-a.elapsed)
 print("clock",os.clock())