2
0

ruci.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. -- Copyright 2009 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local util = require "luci.util"
  4. local rawget, setmetatable = rawget, setmetatable
  5. local ipairs = ipairs
  6. module "luci.rpcc.ruci"
  7. local Proxy = util.class()
  8. function factory(rpccl)
  9. return {
  10. cursor = function(...)
  11. return Proxy(rpccl, rpccl:request("ruci.cursor", {...}))
  12. end,
  13. cursor_state = function(...)
  14. return Proxy(rpccl, rpccl:request("ruci.cursor_state", {...}))
  15. end
  16. }
  17. end
  18. function Proxy.__init__(self, rpccl, objid)
  19. self.__rpccl = rpccl
  20. self.__objid = objid
  21. setmetatable(self, {
  22. __index = function(self, key)
  23. return rawget(self, key) or Proxy[key] or function(self, ...)
  24. local argv = {self.__objid, ...}
  25. return self.__rpccl:request("ruci."..key, argv)
  26. end
  27. end
  28. })
  29. end
  30. function Proxy.foreach(self, config, section, callback)
  31. local sections = self.__rpccl:request("ruci.foreach", {self.__objid, config, section})
  32. if sections then
  33. for _, s in ipairs(sections) do
  34. callback(s)
  35. end
  36. return true
  37. else
  38. return false
  39. end
  40. end