Skip to content

Conversation

@tomblind
Copy link
Contributor

@tomblind tomblind commented Feb 6, 2021

No description provided.

@tomblind tomblind requested review from Perryvw and lolleko February 6, 2021 16:31
- LuaFloorDivision / LuaFloorDivisionMethod (`a // b`, only when targeting Lua 5.3 or later)
- LuaNegation / LuaNegationMethod (`-x`)
- Bitwise operators (only when targeting Lua 5.3 or later)
- BitwiseAnd / BitwiseAndMethod (`a & b`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are Bitwise ops not prefixed with Lua?

Comment on lines 515 to 517
However, there are workarounds that work decently.

One method is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
However, there are workarounds that work decently.
One method is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. For example:
However, there are two possible workarounds. The first one is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. Keep in mind that this is only partially type safe and may require some additional casting.
Example:

const d = v3.dot(v2);
```

There are also language extensions that allow declaring special functions which will transpile to operators. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are also language extensions that allow declaring special functions which will transpile to operators. For example:
The second option was added in version [0.38.0](https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/CHANGELOG.md#0380). You can now use [language extensions](https://typescripttolua.github.io/docs/advanced/language-extensions) that allow declaring special functions which will transpile to operators. This will be completely type safe if the operators are declared correctly.
Example:

Maybe mention this one first?
I think this should be the recommended variant.

export const mul: LuaMultiplication<Vector, Vector, number> & LuaMultiplication<Vector, number, Vector>;
}

const dot = Vector.mul(a, b);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to add types to these consts to demonstrate the point, ie const dot: number = and const scaled: Vector =

const d = v3.dot(v2);
```

There are also language extensions that allow declaring special functions which will transpile to operators. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like duplicate information, couldn't you just refer to the language extensions page? ./language-extensions.md#operator-map-types should do the trick

@Perryvw Perryvw merged commit 475a612 into TypeScriptToLua:source Feb 7, 2021
Sign up for free to 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.

3 participants