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日 14:47:50 -0700
Sam Roberts wrote:
When I require 'blah' it doesn't matter to me how much of the
functionality is implemented in lua, and how much in C, though
I do care what apis I get.
Both are trivially implementable in terms of each other:
Exporting the two simple C functions is the more primitive interface,
compared to exporting a table/userdatum with a metatable and two
metamethods.
Also, note that setenv()/getenv() doesn't allow you to iterate the
environment, at least one more function is required if the
procedural/non-table API approach is taken.
The __index/__newindex interface will not necessarily allow iteration
either. The reason for the separate os.environ() function is to provide
a copy of the current environment to allow for easy modification of it
before passing the modified copy to os.spawn(). This is for the
relative frequent case where one would like to modify the environment of
a spawned (child) process without modifying the current environment.
glob allows patterns matching files in more than one directory, the dir
iterator+pattern match you show doesn't, though with a bit of recursion
its possible, of course, even glob(3) is implemented with opendir(), its
just nice not to have to recode glob() yourself from basic building
blocks, in lua or in C.
This is my point exactly. The directory iterator interface is the more
primitive interface. I guess one of the goals I have in mind is to
reduce the amount of platform-dependent C, preferring instead to write
as much of the code as possible in Lua, which can be shared among all
the API implementations.
glob(3) can be implemented on non-UNIX systems as long as they actually
have a file system. Its just some wildcard matching.
It's difficult to imagine what "/*.c" would do on a Windows system. Not
all systems even use a slash as a directory separator (although I
understand that most Windows APIs accept it in addition to backslash,
even if the command line utilities do not). My point here is also even
providing a function with the name "glob" would imply that it provides
POSIX semantics when in fact it isn't possible to fully do so on
non-POSIX systems.
I definitely think that glob() would be a valuable addition to any Lua
POSIX binding. But the "ex" API does not aim to be a POSIX binding.
-Mark