lua-users home
lua-l archive

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


On Fri, Aug 24, 2012 at 2:35 PM, Rob Hoelz <rob@hoelz.ro> wrote:
>> So how does this work, given that normally the module table is stored
>> and returned each time that require() is called -- does the loader now
>> get re-run each time instead, or are arguments ignored after the first
>> time, or what?
> Excellent question!  I think that the extra arguments feature would
> mainly be used as a configuration mechanism, and authors of modules
> utilizing the feature would have to do so
> under the understanding that the chunk is only evaluated once.

One convention I've seen used is to provide an "init" function that
does necessary setup then returns the module itself, like this:

  local mymodule = require 'mymodule'.init { fancy_mode = true, timeout = 5000 }

It's then the module's responsibility to handle re-initialization in
whatever way is appropriate. Maybe integrating with this convention
somehow would be something to consider.

-Duncan