lua-users home
lua-l archive

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


On May 31, 2013, at 10:07 AM, Owen Shepherd wrote:

> Leo Razoumov wrote:
>> 
>> Isn't  require supposed to set  package.loaded[modname]  to some true
>> value*before*  it executes the module chunk to prevent a possibility
>> of an infinite recursion? 

> There is no appropriate value for package.loaded to be set to until the package code has finished executing. If require set it to some placeholder value, it would just cause errors in other portions of the application.

If capturing the contents of modules were prohibited by convention, this would not be a problem in most cases. This is yet another issue for the localized Lua dialect.

Lua has a single mechanism for naming values symbolically: local. This binds too tightly. In many cases I would prefer #define.

Note that

  define tinsert = table.insert

could have strictly lexical scope, thus not violating "no macros."

But this is not that far from

  static tinsert = table.insert

which is macro-expanded into

  local tinsert
  local function _initializer_1() tinsert=table.insert end
  _ENV.initializer(_initializer_1)

which allows separation of initialization from load; potentially the module system could defer initialization until upstream modules were at least loaded. (The primary goal of separating initializers is to make module reload do something useful in localized Lua, as well as hoisting local symbolic names for things out of loops.)

Jay