Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function table.val_to_str ( v )
  2. if "string" == type( v ) then
  3. v = string.gsub( v, "\n", "\\n" )
  4. if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
  5. return "'" .. v .. "'"
  6. end
  7. return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
  8. else
  9. return "table" == type( v ) and table.tostring( v ) or
  10. tostring( v )
  11. end
  12. end
  13.  
  14. function table.key_to_str ( k )
  15. if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
  16. return k
  17. else
  18. return "[" .. table.val_to_str( k ) .. "]"
  19. end
  20. end
  21.  
  22. function table.tostring( tbl )
  23. local result, done = {}, {}
  24. for k, v in ipairs( tbl ) do
  25. table.insert( result, table.val_to_str( v ) )
  26. done[ k ] = true
  27. end
  28. for k, v in pairs( tbl ) do
  29. if not done[ k ] then
  30. table.insert( result,
  31. table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
  32. end
  33. end
  34. return "{" .. table.concat( result, "," ) .. "}"
  35. end
  36.  
  37. while 1 do
  38. turtle.turnLeft()
  39. turtle.forward()
  40. turtle.turnRight()
  41. local foo = turtle.inspect()
  42. if foo == true or foo == false then
  43. print(foo)
  44. else
  45. print(table.tostring(foo))
  46. end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement