lua-users home
lua-l archive

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


Ken Smith wrote:
I actually did try using lposix and lfs.  Ex looks similar enough that
I didn't bother with it as well.  Python was simpy the better tool for
the job.  It happened that I needed to compute SHA-1 sums and Python
had a module for it.  The Python implementation ended up being faster,
probably owing to os.walk() being faster than explicit iteration with
the methods provided by lposix and lfs.  The native SHA-1 support was
also certainly better than doing a popen to sha1sum.  Although I find
Lua to be a fantastic language, I must say that it has not usurped the
other tools in my toolkit just yet.

There is LuaCrypto http://luacrypto.luaforge.net/ which is a bind to the OpenSSL library. I've used it to generate cryptographically secure random numbers as well as SHA-1 digests.

local evp_new = require "crypto.evp".new
local rand_bytes = require "crypto.rand".bytes

-- generate a session id
local function make_id(expires, email)
        return evp_new"sha1"
                :update(expires)
                :update(email)
                :update(assert(rand_bytes(64)))
                :digest()
end


As far as providing a function like Python's os.walk, lposix could certainly provide a wrapper for the POSIX ftw() and nftw() functions. What stopped you from adding it? :)

The "ex" API doesn't try to provide such a function because it tries to be as low-level as possible while still being as generic (portable) as possible. It's easy to build such a function in Lua on top of either os.dir from "ex" or both os.dir and os.attributes from lfs (LuaFileSystem).


I do understand your point, however. Lua indeed does not have an extensive standard library, and for this reason it isn't an excellent choice for a stand-alone language. But it has other attributes which make it much nicer to use for extending and embedding than most other languages.

					-Mark