-
Notifications
You must be signed in to change notification settings - Fork 22
Added language extensions page #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/advanced/language-extensions.md
Outdated
``` | ||
|
||
:::note | ||
Prefer MultiReturn over the similar [@tupleReturn anotation](./compiler-annotations.md#tuplereturn). MultiReturn can do anything tupleReturn can, with the added benefit of being able to distinguish between actual tuple tables and multiple return values in the type system. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
```ts title=stringfind.ts | ||
declare namespace string { | ||
export function find(haystack: string, needle: string): MultiReturn<[number, number]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if someone will question why this doesn't work the same in the future.
this: void
or @noSelf
would be required. Unless the namespace is defined elsewhere with that very annotation like it is in the playground
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no it works because string
has @noSelfInFile
docs/advanced/language-extensions.md
Outdated
|
||
import { SideBySide } from "@site/src/components/SideBySide"; | ||
|
||
TypeScriptToLua provides several extensions to typescript in the form of types and helper functions. To use these language extensions, add the types to your `tsconfig.json`: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
docs/advanced/language-extensions.md
Outdated
|
||
## MultiReturn Type | ||
|
||
This language extension allows typing of Lua functions that return multiple values. For example, consider Lua's `string.find`, it returns two indices: the start of the found substring and the end of the found substring. In TypeScript, function can only return one value so a special type is needed to indicate to tstl there are multiple return values. This is the `MultiReturn<>` type. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
No description provided.