lua-users home
lua-l archive

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


On Tue, Jul 21, 2009 at 7:28 PM, Sam Roberts<vieuxtech@gmail.com> wrote:
> On Tue, Jul 21, 2009 at 1:21 AM, steve donovan<steve.j.donovan@gmail.com> wrote:
>> On Tue, Jul 21, 2009 at 10:05 AM, startx<startx@plentyfact.org> wrote:
>>> 2) my second question is about the use of namespaces: as i have quite
>>> a lot of functions, i would like to use a "subnamespace" to group the
>>> functions to something like:
>>>
>>> myproject.core.do_something()
>>
>> It's actually a common pattern, e.g. look at LuaSocket.   If on the
>> LUA_PATH there is a directory myproject, which contains core.lua, then
>> require 'myproject.core' will pull it in. If you use module() then the
>> 'namespaces' are automatically created for you.
>
> Maybe I misunderstand what you mean by "namespaces are automatically
> created for you", because
> it doesn't look like it to me.
>
> I would expect after require"hi.bye" to be able to access "hi.bye", if
> namespace were created, but that isn't how it works, as far as I can
> tell.

You still need the full namespace path in the module() call, so
module("hi.bye") instead of module("bye"). I think what he meant is
that it will handle creating the "hi" table for you automatically if
it does not already exist.

Also, consider using module(...) as this will automatically use
"hi.bye" which is passed in to the function as a parameter by the
require loader.

-Duncan