[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: package.config is a string?
- From: HyperHacker <hyperhacker@...>
- Date: Fri, 11 Jun 2010 22:13:15 -0600
On Fri, Jun 11, 2010 at 21:58, David Manura <email@example.com> wrote:
> On Thu, Jun 10, 2010 at 11:03 PM, joshua simmons <firstname.lastname@example.org> wrote:
>> Is there any great reason for package.config to be a string of elements
>> separated by new lines as opposed to a table of individual elements?
>> Especially when it contains very useful data like the system's path
> Having it be a table makes some sense, at the cost of a few extra
> objects in memory that might never be used in a program.
> The question I have is why package.path and package.cpath are strings
> rather than arrays. If they were arrays--like their analogues in
> Python (sys.path), Perl (@INC), and Ruby ($:) and unlike in shell
> scripting (PATH), with Tcl perhaps in-between--user code wouldn't have
> to worry about parsing and constructing them using the value of
> LUA_PATH_SEP (";"), and loadlib.c:pushnexttemplate wouldn't need to
> re-parse it on each require.
> To append a path, which of these do you prefer? Which would users
> more likely write correctly? Which is easier to later undo?
> table.insert(package.path, "./mylib/?.lua")
> package.path = package.path .. package.config:sub(3,3) .. "./mylib/?.lua"
> Perl, BTW, has a very small convenience notation in the form of a
> pragma module  that expressed in Lua might look like `import("lib",
> "./mylib/?.lua")`, where `import(a,...)` is defined roughly as
> `require(a):__import(...)`, which in turn here does
> `table.insert(package.path, x)` for each `x` in `...`. So, to load
> ./mylib/foo.lua, you would do something like `import("lib",
> "./mylib/?.lua"); import("foo")`. An even shorter form (Ruby example
> ) would be `lib "./mylib/?.lua"` or just `lib "./mylib"` setting
> all ?.lua, ?.so, and ?/init.lua (Steve: suggest to penlight). Perl 6,
> I understand, might also allow the search path to be a lexical so that
> changes to it are limited to lexical scope .
>  http://lua-users.org/lists/lua-l/2010-01/msg00456.html
>  http://blog.ljstech.net/2007/02/ruby-lib-path-manipulations.html
>  http://irclog.perlgeek.de/perl6/2010-06-12#i_2426382
These are both good points, and I'd like to also point out that
package.config doesn't seem to be in the 5.1 manual.
Sent from my toaster.