My dotfiles. Period.

functions.lua 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. socket = require "socket"
  2. function shortname()
  3. local long = socket.dns.gethostname()
  4. return string.gmatch(long, '[^.]+')()
  5. end
  6. function get_queue(mbox)
  7. --TODO: try to get tail
  8. return mbox.FILTER_QUEUE:is_newer(84)
  9. end
  10. function _partinf_compare(a, b)
  11. if not type(a) == type(b) then
  12. return false
  13. end
  14. if type(a) == 'number' then
  15. return a == b
  16. elseif type(a) == 'string' then
  17. return a:lower() == b:lower()
  18. end
  19. end
  20. function has_part_like(query, structure)
  21. if structure == nil then
  22. return false
  23. end
  24. for partid, partinf in pairs(structure) do
  25. local part_answer = true
  26. -- check all query parts
  27. for qkey, qvalue in pairs(query) do
  28. value = partinf[qkey]
  29. if not _partinf_compare(value, qvalue) then
  30. part_answer = false
  31. break
  32. end
  33. end
  34. if part_answer then
  35. return true
  36. end
  37. end
  38. return false
  39. end
  40. function filter_part_like(query, seq)
  41. result = Set {}
  42. for _, mesg in ipairs(seq) do
  43. mbox, uid = table.unpack(mesg)
  44. structure = mbox[uid]:fetch_structure()
  45. if has_part_like(query, structure) then
  46. table.insert(result, mesg)
  47. end
  48. end
  49. return result
  50. end