
Untitled
By: a guest on
Apr 6th, 2011 | syntax:
Lua | size: 1.50 KB | views:
197 | expires: Never
rule_actions = {}
rules_done = {}
function do_rule(name)
assert (rule_actions[name], "no such rule "..tostring(name))
return rule_actions[name]()
end
function do_action(act)
if type(act) == "string" then
return os.execute(act) == 0
elseif type(act) == "function" then
return act()
end
end
function rule(name)
assert(not rule_actions[name], "rule "..tostring(name).." has already been defined!")
return function(dependencies)
return function(actions)
rule_actions[name] = function()
if rules_done[name] then
return true
end
for k, v in pairs(dependencies) do
if not do_rule(v) then
return false
end
end
if type(actions) == "table" then
for k, v in pairs(actions) do
if not do_action(v) then
return false
end
end
else
if not do_action(actions) then
return false
end
end
rules_done[name] = true
return true
end
end
end
end
rule "printhello" {} [[
echo hello
]]
rule "printhi" {} {
function() print ("HI") return true end
}
rule "all" {"printhello", "printhi"} {}
do_rule "all"