draugath

rmlpairs - main.lua

Jan 10th, 2013 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. declare('rmlpairs', {})
  2. local context
  3. local docs
  4. local options
  5.  
  6. function rmlpairs.init()
  7.     context = rmlui.contexts[1]
  8.     docs = rmlui.contexts[1].documents
  9.     options = nil
  10.     for i = 1, 10 do
  11.         if (docs[i].title == "Options") then
  12.             options = docs[i]
  13.             break
  14.         end
  15.     end
  16.     if (options == nil) then
  17.         options = {"Options Document not found"}
  18.     end
  19. end
  20.  
  21.  
  22. local function proxyipairs(thing)
  23.     console_print("ipairs()\n"..string.rep("-", 50))
  24.     for i, v in ipairs(thing) do
  25.         console_print("  ["..i.."] = "..tostring(v))
  26.     end
  27. end
  28.  
  29. local function proxypairs(thing)
  30.     console_print("pairs()\n"..string.rep("-", 50))
  31.     for k, v in pairs(thing) do
  32.         console_print("  ["..k.."] = "..tostring(v))
  33.     end
  34. end
  35.  
  36. local function pcallwrapper(func, ...)
  37.     local retval, err = pcall(func, ...)
  38.     if (not retval) then
  39.         console_print(err)
  40.     end
  41. end
  42.  
  43. function rmlpairs.print(thing)
  44.     if (not thing) then return end
  45.     local thing_name = tostring(thing):match("^%S+")
  46.     if (thing_name:match("Proxy")) then
  47.         console_print("\n"..thing_name)
  48.         pcallwrapper(proxyipairs, thing)
  49.         console_print("\n")
  50.         pcallwrapper(proxypairs, thing)
  51.     end
  52. end
  53.  
  54. function rmlpairs.printall()
  55.     rmlpairs.print(rmlui.contexts)
  56.     rmlpairs.print(docs)
  57.     rmlpairs.print(options.attributes)
  58.     rmlpairs.print(options.child_nodes)
  59. end
  60.  
Advertisement
Add Comment
Please, Sign In to add comment