When used frequently, however, it can be a performance win since it
eliminates a table lookup. I've started to use the convention:
local Corge_foo = Corge.foo
- as before, it checks that you only use declared fields in the module, unless you have declared the module as "free"
- it replaces all instances of the module with a local variable
- it declares the corresponding local var at the appropriate place, i.e. either at the beginning of the file for base libraries, or after the relevant require() call for loaded libraries.
To enable autolocal compilation, use option -a. To see the AST after transformation, use -d. You're still advised to use the latest git snapshot of metalua.
An illustrative example:
local x = { }
-- This module declares table 'Corge',
-- and advertises it in its .dlua interface file:
require 'corge'table.insert(x, 'foo')
Corge.foo(x)This is compiled into (tilde characters are used into identifier names, to prevent clashes with legal names):
local x = { }require 'corge'
local ~Corge~foo = Corge.foo~table~insert(x, 'foo')
~Corge~foo(x)New version:
http://metalua.luaforge.net/metalint-0.2.tgz. Usual warnings: it's an undertested quick'n dirty hack, which is likely to have bugs in corner cases.