[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Packaging and importing
- From: Chris Marrin <chris@...>
- Date: Sat, 13 Aug 2005 08:18:10 -0700
I have been trying to learn about Lua 5.1's new packaging mechanism. I
have two main questions. First, there seems to be some contradictions to
how it works. In looking at the file lom.lua in the luaexpat package, it
looks like you can go:
local a = foo.bar(5)
This is nice and simple. But in reading the message that describes how
it works at:
There are a couple of things that don't seem to allow this. First of
all, it looks like the spec says you have to go:
local foo = require "foo"
local a = foo.bar(5)
In other words, does the package get put into the global namespace or
not? Also, the spec seems to say that it searches for files of the form
?.so or ?.dll, but it says nothing about packages written in Lua itself.
In looking at lom.lua it looks like this is certainly possible.
Is my problem that the feature is not yet well documented? If so, that
is fine. I just want a clear idea of what the functionality will be,
because that leads me to my second question:
Does Lua have any capability for importing names from a package into the
local namespace, like you see in Python? In that language, you have this:
from foo import bar
from foo import *
In the first form, this is pretty much equivalent to require in Lua. It
puts a symbol called "foo" in the namespace and all its functionality
can be accessed from that. So you would go:
a = foo.bar(5)
just like in Lua. The second form looks at the foo package, extracts its
bar symbol and adds that to the namespace. So you can now go:
a = bar(5)
The last form looks into foo and extracts ALL its symbols and adds them
to the namespace.
Has this issue been discussed? I have found a few threads discussing
import and require in general (I assume that these are what resulted in
the current spec) but I never saw a resolution about the "from...import"
issue. This looked like a promising comment from Mike Pall:
but the "from...import" argument didn't really go anywhere.
One other detail of this has to do with specific namespaces. On the list
I have seen concern about putting package names into the GLOBAL
namespace. Because then some module could rely on a package getting
loaded by another. But Python has the concept of module specific
namespaces. So that, if file A imported package foo, the name foo would
be available throughout A, but not to another file B. I know Lua has the
concept of environments (which I am still trying to understnad fully) so
maybe that deals with this issue as well.
Anyway, just trying to understand how all this packaging stuff works...
chris marrin "As a general rule,don't solve puzzles
email@example.com that open portals to Hell" ,,.