[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] vstruct - 1.0 beta 2
- From: Ben Kelly <ranavin@...>
- Date: Thu, 31 Jul 2008 19:46:16 -0400
Jerome Vuarand wrote:
> 2008/7/25 Ben Kelly <ranavin@gmail.com>:
>>> The tricky module-mechanism is not easy to
>>> understand. I mean things like this
>>>
>>> local name = (...):gsub('%.[^%.]+$', '')
>>> local read = require (name..".read")
>>>
>>> and similar lines.
>> I'm not actually entirely happy with that; it feels ugly and slightly
>> hackish. I have yet to come up with a better way, though.
>
> The standard 'module' function does that work. You can replace:
>
> local name = (...):gsub('%.[^%.]+$', '')
> local read = require (name..".read")
> local write = require (name..".write")
> local compile = {}
>
> with:
>
> module(..., package.seeall)
> local read = require (_PACKAGE.."read")
> local write = require (_PACKAGE.."write")
> local compile = _M
The problem is that I want the submodules to be entirely local to the
module; end users shouldn't be able to see struct.read/struct.write
without explicitly requiring it. Using module() means going out and
clearing away the extra table entries it creates first.
On the other hand, I didn't know about _PACKAGE. Handy. I need to think
further on this.
Ben