lua-users home
lua-l archive

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


2010/7/5 Alexander Gladysh <agladysh@gmail.com>:
> So, the question is — how to introduce such abstractions to Lua (not
> as the language changes, of course, but as a specialized module).

Many tools you may need are available as command line utilities. Shell
scripts are particularly well suited to use them, they are integrated
in the syntax. With stock Lua, you have to use os.execute or io.popen.

What you can do is introduce some helper code to run external
utilities more easily. For example you could put a __index hook on _G
(or a module), that would check if a command line utility with the
given key exist in the path, and would wrap a call to io.popen in a
Lua function, with proper whitespace escaping. For example you could
then write :

local files = find('.', '-name' '*foo*')
for _,file in files:match('[^\n]+') do
    print(stat('%n is a %F', file))
end

Where find and stat are wrappers for the command line tools.