[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: DSL in lua
- From: Coda Highland <chighland@...>
- Date: Wed, 5 Dec 2012 22:51:49 -0800
The = is just an efficiency thing, you can write it without it. It's
the commas that are important.
It'd probably end up looking something like
function owner(name) return {key='owner', value=name} end
and then the function returned by directory() would iterate over the
members of the table passed to it and construct a table based on that.
/s/ Adam
On Wed, Dec 5, 2012 at 10:48 PM, Vasiliy Tolstov <v.tolstov@selfip.ru> wrote:
> Thanks. But = sign i think is ambigious... How can i avoid using = sign?
>
> 2012/12/6 Dirk Laurie <dirk.laurie@gmail.com>:
>> You're a few commas away from legal Lua syntax.
>>
>> directory "/etc/" {
>> owner "root",
>> group "wheel",
>> mode "0755",
>> action "create",
>> }
>>
>> It can be done (functions owner etc would have to store
>> their argument somewhere) but a few equal signs makes the
>> Lua code efficient:
>>
>> directory "/etc/" {
>> owner="root",
>> group="wheel",
>> mode="0755",
>> action="create",
>> }
>>
>> The code would be (not tested):
>>
>> function directory(dirname)
>> return function(t)
>> os.execute ("mkdir %s; chown %s.%s %s; chmod %s %s"):
>> format(dirname,t.owner,t.group,dirname,t.mode,dirname)
>> end
>> end
>>
>> Or one could replace the `{`..`}` by `[[`..`]]` and insert
>> a small parser that extracts the fields from the string.
>>
>
>
>
> --
> Vasiliy Tolstov,
> Clodo.ru
> e-mail: v.tolstov@selfip.ru
> jabber: vase@selfip.ru
>