Advertisement
Guest User

return table LUA

a guest
Dec 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function getAllData(t, prevData)
  2. -- if prevData == nil, start empty, otherwise start with prevData
  3. local data = prevData or {}
  4.  
  5. -- copy all the attributes from t
  6. for k,v in pairs(t) do
  7. data[k] = data[k] or v
  8. end
  9.  
  10. -- get t's metatable, or exit if not existing
  11. local mt = getmetatable(t)
  12. if type(mt)~='table' then return data end
  13.  
  14. -- get the __index from mt, or exit if not table
  15. local index = mt.__index
  16. if type(index)~='table' then return data end
  17.  
  18. -- include the data from index into data, recursively, and return
  19. return getAllData(index, data)
  20. end
  21.  
  22. m = peripheral.wrap("top")
  23.  
  24. print(getAllData(m))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement