misc.lua 592 B

12345678910111213141516171819202122232425262728
  1. --- Miscellaneous functions
  2. -- @module modpol.util.misc
  3. modpol.util = {}
  4. --- Returns a copy of the table inputted
  5. -- @function modpol.util.copy_table
  6. -- @param t table to copy
  7. -- @return copy of table
  8. function modpol.util.copy_table(t)
  9. local t2 = {}
  10. for k,v in pairs(t) do
  11. t2[k] = v
  12. end
  13. return t2
  14. end
  15. --- Returns the number of elements in a pairs table
  16. -- @function modpol.util.num_pairs
  17. -- @param t pairs table
  18. -- @return number of elements in pairs table
  19. function modpol.util.num_pairs(t)
  20. local i = 0
  21. for k,v in pairs(t) do
  22. i = i + 1
  23. end
  24. return i
  25. end