[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: DSL in lua
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 6 Dec 2012 10:01:50 +0200
On Thu, Dec 6, 2012 at 8:53 AM, Vasiliy Tolstov <v.tolstov@selfip.ru> wrote:
> 1-2) can you provide me simple exmple, please.
function directory(path)
local t = {path=path}
return function (spec)
for key,value in pairs(spec) do
t[key] = value
end
create_directory(t) ---> actually makes the directory
end
end
So it's a function that returnsa function - or more accurately creates
a closure that has a reference to the local t (an 'upvalue')
If we had "directory '/tmp/foo' { owner='root' }" then
create_directory will be called with the table
{path='/tmp/foo',owner='root'}
steve d.