[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Configuration file rewrite
- From: Sean Conner <sean@...>
- Date: Wed, 21 Dec 2011 11:44:13 -0500
It was thus said that the Great Sime Ramov once stated:
> Hello,
>
> I only recently started learning Lua and I am amazed. Unfortunately, I
> am not a programmer, so I fail to take bigger advantage of the language.
>
> First task I set to myself was to rewrite herbstluftwm[1] configuration
> file from shell to Lua.
>
> herbstluftwm is a nice window manager, configured at runtime via ipc
> calls from `herbstclient`.
>
> While I managed to rewrite the configuration file, that's all I did, a
> line by line rewrite of the shell code. There is nothing advanced or
> elegant about it. I haven't actually solved any problems.
>
> Here is the file: http://dl.ramov.com/herbstluftwm.lua
>
> Any ideas to make it better, i.e. maybe some clever use of tables or
> some higher order functions etc?
I would construct the configuration file as:
-----[ hc.conf ]-----------------
set =
{
always_show_frame = 0,
default_frame_layout = 2,
frame_bg_transparent = 1,
frame_broder_active_color = '#262626',
-- ...
}
keybindings =
{
['Mod1-q'] = 'quit',
['Mod1-Shift-r'] = 'reload',
['Mod1-Shift-c'] = 'close',
-- Layout
['Mod1-r'] = 'remove',
['Mod1-space'] = 'cycle_layout 1',
}
mousebindings =
{
-- ...
}
-- etc.
I think this looks better, and is simpler to understand than wrapping
everything in calls to a function. Then, have another file to actually load
and process this file:
-----[ runme.lua ]-----------------------------
dofile("hc.conf")
for _,section in ipairs { 'set' , 'keybindings' , 'mousebindings' } do
for name,value in pairs(section) do
os.execute(string.format("herbstclient %s %s",name,tostring(value)))
end
end
Even better, modify the window manager to load and process the Lua file
directly.
-spc (Who recently converted a program to use Lua for configuration [1])
[1] http://boston.conman.org/2011/11/28