summaryrefslogtreecommitdiff
path: root/lib/lace/builtin.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lace/builtin.lua')
-rw-r--r--lib/lace/builtin.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua
index 209916d..a45051f 100644
--- a/lib/lace/builtin.lua
+++ b/lib/lace/builtin.lua
@@ -13,6 +13,8 @@ local function compiler()
return require "lace.compiler"
end
+--[ Allow and Deny ]------------------------------------------------
+
local function _do_return(exec_context, result, reason, cond)
if #cond > 0 then
-- Run the conditions
@@ -40,6 +42,35 @@ end
builtin.allow = _return
builtin.deny = _return
+--[ Default for Allow and Deny ]------------------------------------
+
+function builtin.default(compcontext, def, result, reason, unwanted)
+ assert(def == "default", "Somehow, builtin.default got something odd")
+ if type(result) ~= "string" then
+ return compiler().error("Expected result, got nothing")
+ end
+ if result ~= "allow" and result ~= "deny" then
+ return compiler().error("Result wasn't allow or deny", {2})
+ end
+ if type(reason) ~= "string" then
+ reason = "Default behaviour"
+ end
+ if unwanted ~= nil then
+ return compiler().error("Unexpected additional content", {4})
+ end
+
+ if compcontext[".lace"].default then
+ return compiler().error("Cannot change the default")
+ end
+
+ compcontext[".lace"].default = { result, reason }
+
+ return {
+ fn = function() return true end,
+ args = {}
+ }
+end
+
return {
commands = builtin,
}