lua-users home
lua-l archive

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

Alexander Gladysh writes:
> I [organize] each file as follows:
>     local foo, bar, baz = import 'path/to/file.lua' { 'foo', 'bar', 'baz' }
> ...
> However there is one weak spot -- the import function. It is too easy
> to mess things up and write arguments in wrong order:
>     local foo, bar, baz = import 'path/to/file.lua' { 'bar', 'baz', 'foo' }

local Corge = require 'qux.quux.Corge'
local foo =
local bar =
local baz = Corge.baz

There can, however, be an advantage in removing some or all of the last three
lines and, for example, referencing "" rather than "foo" in the code
since the prefix "Corge." indicates explicitly where the function "foo" comes
from, and the Hungarian-ish prefix makes obvious the fact that "foo" is external
to the current module.  The "local foo =" is called a "static import"
in a some other languages and its use is recommended only sparingly[1].