lua-users home
lua-l archive

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


Sam Roberts wrote:
On Tue, Oct 17, 2006 at 05:01:15PM +0200, Natanael Copa wrote:
What do you think about this as a start:

env.getenv(name)
env.setenv(name, value)
env.environ()

What about:

  env[name]
  env[name] = value

This is easy enough to do in pure Lua; it doesn't need to be provided by a binary module, IMHO:

require "ex"
local environ = {}
function environ:__index(k) return os.getenv(k) end
function environ:__newindex(k,v) os.setenv(k,v) end
environ = setmetatable({}, environ)

I'd like to add "glob" but I don't know how it can be implemented in windows.

Worst case - code it by hand

Sure. Again, this is something that pure Lua can do when provided a primitive directory iterator:

require "ex"
for e in os.dir"." do
   if e.name:match"[.]html$" then
      print(e.name)
   end
end

Note that if you want /bin/sh globbing as specified by POSIX, then you'd be better off actually wrapping glob(3) itself. However, be sure that in this case your Lua program is targetting POSIX and since the POSIX glob() semantics are something that do not exist on other systems, your program is inherently non-portable to non-POSIX, non-UNIX-y systems.

					-Mark