[lltx] code style

Manuel Pégourié-Gonnard mpg at elzevir.fr
Wed May 19 15:19:31 CEST 2010


Le 19/05/2010 13:58, Will Robertson a écrit :
> On 19/05/2010, at 7:29 PM, Arthur Reutenauer wrote:
> 
>>> local splitpath, expandpath = file.split_path, kpse.expand_path
>>> local gsub, match, rpadd    = string.gsub, string.match, string.rpadd
>>
>>  It's not obfuscation, it's Hans' style :-)  I'm not a big fan either,
>> but I got used to it, reading ConTeXt's Lua source code.
> 
> Well, that's the whole point -- once you're used to it, it's fine :)

Personally, I don't like this style very much either, fwiw. I don't doubt you
can get used to any style, but anyway.

> But it's just a bit inconsistent when you've got expandpath (=kpse.expand_path) but then go and use kpse.expand_var in the same file. And it adds an extra line of code to the beginning of the script.
> 
Agreed.

>> I think I've seen it under Roberto's pen in _Programming in Lua_ but
>> can't be sure.
> 
> I do seem to recall he mentions it, yes...
> 
It is probably mentioned as a standard way to deal with modules. The easiest way
to "import" variables in a module is to declare it using

module('foobar', package.seeall)

but it has the following funny effect: foobar.string will be the same as the
global string table.

Another, more paranoid way of importing symbols in modules is to import them as
locals, eg:

local pairs, ipairs, format = pairs, ipairs, string.format
module('foobar')

Here the goal is not really to shoten names, but to keep a closer control about
which symbols are available in the scope of the module, and avoid the above
mentioned funny effect.

(Also, locals are accessed faster than globals, as Élie mentioned, but I doubt
this is relevant except in very special cases.)

> I didn't mean to imply that I preferred tabs; on the contrary.
> I personally like 2-space-indenting, but mostly only from lots of TeX use, where command names get rather long.
> 
Currently, I'm indenting my TeX code with two spaces, my stand-alone Lua code
with four spaces, and for Lua code embedded in dtx files... hum, I don't know. A
mix of both, I'm afraid.

Manuel.


More information about the lualatex-dev mailing list