Skip to content

Operator overload - #1

Open
JonathanOrr wants to merge 2 commits into
jonstoler:masterfrom
JonathanOrr:operator-overload
Open

Operator overload#1
JonathanOrr wants to merge 2 commits into
jonstoler:masterfrom
JonathanOrr:operator-overload

Conversation

@JonathanOrr

Copy link
Copy Markdown

This pull request aims to add operator-overloading to the classes created by the original library

The usage example of the added feature is as follows:

require"class"Vector2=Class:extend()
functionVector2:init(x, y)
self.x=xself.y=yend-- attributes --Vector2:set{x=0, y=0}
-- operator overloading --functionVector2:__add(other)
returnVector2(
self.x+other.x,
self.y+other.y
)
endfunctionVector2:__tostring()
returnstring.format("Vector2(%f, %f)", self.x, self.y)
end-----------------------------------------------------------localvec1=Vector2(1, 2)
localvec2=Vector2(3, 4)
print(vec1+vec2)

The output of the example above is:

 "Vector2(4.0, 6.0)"

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@JonathanOrr