lua-users home
lua-l archive

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


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