lua-users home
lua-l archive

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


On Thu, Jul 1, 2010 at 23:39, Javier Guerra Giraldez <javier@guerrag.com> wrote:
> On Thu, Jul 1, 2010 at 2:34 PM, Petite Abeille <petite.abeille@gmail.com> wrote:
>> FWIW, in modules, I use locals as an import mechanism, irrespectively of "performance" consideration.

> same here.  i really don't like the 'seeall' option to module()

In my current engine it is forbidden to create and access new globals.

The only allowed globals are ones from standard Lua libraries — just
because I'm too lazy to really enforce aliasing them at the top of the
file. This feature is in my TODO list for years :-). Anyway,
developers are encouraged to do such aliasing.

The other allowed global is an import() function (a wrapper around
loadfile() with cache).

So, my Lua files usually look like this:

----------
local print = print
local foo, bar = import 'foobar.lua' { 'foo', 'bar' }

local baz = function() print("baz") end

local qux = function() print("qux") end

return
{
  baz = baz;
  qux = qux;
}
----------

The import() function, probably, should be reimplemented as a wrapper
around require() instead of loadfile() — to allow path searching etc.
Current implementation is too ecosystem-dependent.

Alexander