lua-users home
lua-l archive

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

On Sat, Mar 22, 2008 at 9:08 AM, Mark Hamburg <> wrote:
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 =

I've modified the metalint hack I've posted a couple of days ago (, so that it automates this task. More precisely:
- 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')

This is compiled into (tilde characters are used into identifier names, to prevent clashes with legal names):

local x = { }
require 'corge'
local ~Corge~foo =
~table~insert(x, 'foo')

New version: Usual warnings: it's an undertested quick'n dirty hack, which is likely to have bugs in corner cases.