summaryrefslogtreecommitdiff
path: root/builtin/common/misc_helpers.lua
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2021-06-04 21:22:33 +0200
committerGitHub <noreply@github.com>2021-06-04 21:22:33 +0200
commit8f085e02a107dd8092393935bfa1bba71d2546d2 (patch)
tree977942563431784d65b5f5066d04669d522600e6 /builtin/common/misc_helpers.lua
parente15cae9fa0f99f597f349a7ba07d149cd91cc2d8 (diff)
downloadminetest-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.lua28
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