lua-users home
lua-l archive

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


On Thu, Feb 08, 2007 at 07:46:04AM -0200, Luiz Henrique de Figueiredo wrote:
> > but the return makes it look less like a config file.
> 
> Drop the return and the table constructor all together and use a custom
> dofile, one that adds "return {" at the beginning and "}" at the end.
> This will allow (and restrict) config files to be a series assignments.
> On the other hand, you'll need commas or semicolons after each assignments;
> semicolons seem better in this case.

It doesn't prevent non-config-file-like behavior, like
"x = function() ... end();", and by restricting the syntax and
preventing doing things naturally, it'll tend to encourage doing
things unnaturally.

It also makes it inconvenient to compile the files, which can be useful
(depending on the "config files").  I've witten scripts to process and
compile Lua scripts, and it's much nicer to be able to compile them in-
place.

The environment approach lets a Lua script be a real Lua script while
still allowing simple configuration files to just be a bunch of
assignments, though.  (I'd also __index it to the caller environment,
unless I really wanted a restricted environment.)

-- 
Glenn Maynard