lua-users home
lua-l archive

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


Lua 5.0 (pre-release) -- quick comments

I also wasn't able to get readline support, compiling in linux (slackware
8.1, mandrake 9.0, debian 3).

Other than that the compiles worked great.

I like the new info on tail recursion, works fine (did simple tail-call
20,000 times); simple script:
	-- test1
	format = string.format
	printf = function(...) print(format(unpack(arg))) end

	function ff(n)
	    local s = 0
	    local times = 0
	    local norig = n
	    local ff1
	    ff1 = function (n)
		if n <= 0 then
		    return s, times

		end
		s = s + n
		times = times + 1
		printf("(called with %d) for #%d, adding %d gives %d",
			norig, times, n, s)
		return ff1(n-1)
	    end
	    return ff1(n)
	end

	n = tonumber(arg[1])
	printf("ff(%d) = %d (called %d times)", n, ff(n))

and, to test: "lua50c test1 20000"

popen also works fine, although I couldn't find it referenced in the
manual (also looked in io.open).  (Doing a grep I found it in
lib/liolib.c). I exercised it with a simple script to find the 5
largest files in my current directory:

    proc = io.popen("ls -l | sort +4nr", "r")
    n = 0
    while 1 do
        line = proc:read()
        n = n + 1
        print(string.format("%04d %s", n, line))
        if n == 5 then break end
    end
    proc:close()

// Joe