mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
Vector3: Implement __concat operator overloading
Now you can do this: local v = wea.Vector3.new(3, 4, 5) print(v.."yay")
This commit is contained in:
parent
0b379c48cb
commit
0fef39d707
2 changed files with 34 additions and 0 deletions
28
.tests/Vector3/concat.test.lua
Normal file
28
.tests/Vector3/concat.test.lua
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
|
describe("Vector3.__concat", function()
|
||||||
|
it("should work when concatenating a Vector3 + Vector3", function()
|
||||||
|
local a = Vector3.new(3, 4, 5)
|
||||||
|
local b = Vector3.new(6, 7, 8)
|
||||||
|
|
||||||
|
assert.are.is_true(
|
||||||
|
type(tostring(a .. b)) == "string"
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work when concatenating a string + Vector3", function()
|
||||||
|
local a = "yay"
|
||||||
|
local b = Vector3.new(6, 7, 8)
|
||||||
|
|
||||||
|
assert.are.is_true(
|
||||||
|
type(tostring(a .. b)) == "string"
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work when concatenating a Vector3 + string", function()
|
||||||
|
local a = Vector3.new(3, 4, 5)
|
||||||
|
local b = "yay"
|
||||||
|
|
||||||
|
assert.are.is_true(
|
||||||
|
type(tostring(a .. b)) == "string"
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end)
|
|
@ -389,5 +389,11 @@ function Vector3.__tostring(a)
|
||||||
return "("..a.x..", "..a.y..", "..a.z..")"
|
return "("..a.x..", "..a.y..", "..a.z..")"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Vector3.__concat(a, b)
|
||||||
|
if type(a) ~= "string" then a = tostring(a) end
|
||||||
|
if type(b) ~= "string" then b = tostring(b) end
|
||||||
|
return a .. b
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return Vector3
|
return Vector3
|
||||||
|
|
Loading…
Reference in a new issue