lua-users home
lua-l archive

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


On Sun, 31 Jan 2010 17:49:15 -0200
Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:

> Although Lua is nice :-), sometimes it's best to provide the user
> with a simple shell-like command-line interface. But if you do so,
> you'll have to parse and execute the line. lcl does that for you. A
> line like print us $me and $you
> is evaluated in Lua as
> 	print("us",me,"and",you)

It was suggested on #lua this evening that I reply to this with a trick
I've used for processing configuration files.

I used to use this sort of shape:

settings {
	foo = "bar",
	bar = "baz"
}

And such.  Unfortunately, this has the problem that the syntax has
several gotchas that people unfamiliar with Lua will be tripped-up by.

I changed the format to this:

foo "bar"
bar "baz"

This can be done quite easily using this one-liner having loading the
configuration file with loadstring:

setfenv(configfilefunc, setmetatable({},{__index=function(t,k) return
function(v) settings[k]=v end end}))


B.