lua-users home
lua-l archive

Re: DSL in lua

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


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.

AltStyle によって変換されたページ (->オリジナル) /