Re: about lposix
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: about lposix
- From: Mark Edgar <medgar@...>
- Date: 2006年10月17日 12:04:49 -0700
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