diff options
author | DS <vorunbekannt75@web.de> | 2021-06-04 21:22:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 21:22:33 +0200 |
commit | 8f085e02a107dd8092393935bfa1bba71d2546d2 (patch) | |
tree | 977942563431784d65b5f5066d04669d522600e6 /builtin/common/misc_helpers.lua | |
parent | e15cae9fa0f99f597f349a7ba07d149cd91cc2d8 (diff) | |
download | minetest-8f085e02a107dd8092393935bfa1bba71d2546d2.tar.gz minetest-8f085e02a107dd8092393935bfa1bba71d2546d2.tar.bz2 minetest-8f085e02a107dd8092393935bfa1bba71d2546d2.zip |
Add metatables to lua vectors (#11039)
Add backwards-compatible metatable functions for vectors.
Diffstat (limited to 'builtin/common/misc_helpers.lua')
-rw-r--r-- | builtin/common/misc_helpers.lua | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index d5f25f2fe..64c8c9a67 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -432,21 +432,19 @@ function core.string_to_pos(value) return nil end - local p = {} - p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") - if p.x and p.y and p.z then - p.x = tonumber(p.x) - p.y = tonumber(p.y) - p.z = tonumber(p.z) - return p - end - p = {} - p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$") - if p.x and p.y and p.z then - p.x = tonumber(p.x) - p.y = tonumber(p.y) - p.z = tonumber(p.z) - return p + local x, y, z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") + if x and y and z then + x = tonumber(x) + y = tonumber(y) + z = tonumber(z) + return vector.new(x, y, z) + end + x, y, z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$") + if x and y and z then + x = tonumber(x) + y = tonumber(y) + z = tonumber(z) + return vector.new(x, y, z) end return nil end |