summaryrefslogtreecommitdiff
path: root/lib/lace/builtin.lua
blob: 209916db363715895bf2c2cdd33f516eddcb4346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- lib/lace/builtin.lua
--
-- Lua Access Control Engine -- Builtin commands for Lace
--
-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
--
-- For Licence terms, see COPYING
--

local builtin = {}

local function compiler()
   return require "lace.compiler"
end

local function _do_return(exec_context, result, reason, cond)
   if #cond > 0 then
      -- Run the conditions
   end
   return result, reason
end

local function _return(compcontext, result, reason, ...)
   if result ~= "allow" and result ~= "deny" then
      return compiler().error("Unknown result: " .. result, {1})
   end
   if type(reason) ~= "string" then
      return compiler().error("Expected reason, got nothing")
   end
   return {
      fn = _do_return,
      args = {
	 result,
	 reason,
	 {...}
      }
   }
end

builtin.allow = _return
builtin.deny = _return

return {
   commands = builtin,
}