command_basics.lua 701 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. local function parse_int(str)
  2. local negative = string.match(str, "[%-]")
  3. local num = string.match(str, "[%d]+")
  4. local sign = (negative and -1) or 1
  5. local value = 0
  6. for d in string.gmatch(num or "", "%d")
  7. do
  8. value = value * 10 + d
  9. end
  10. return sign * value, type(num) == "string"
  11. end
  12. function map_making_toolkit.parse_args(param)
  13. local vectors = {}
  14. local i = 1
  15. for str in string.gmatch(param, "([%-%d]+)")
  16. do
  17. local n, worked = parse_int(str)
  18. if not worked
  19. then
  20. return false
  21. end
  22. vectors[i] = n
  23. i = i + 1
  24. end
  25. if not i == 7
  26. then
  27. return false
  28. end
  29. return true,
  30. vector.new(vectors[1], vectors[2], vectors[3]),
  31. vector.new(vectors[4], vectors[5], vectors[6])
  32. end