-
Notifications
You must be signed in to change notification settings - Fork 470
Description
The Luau analyzer supports (undocumented) declaration files, which allow developers of Luau bindings to add types and documentation to their APIs. These files are in turn used by the Luau analyzer (and, in turn, by the third party Luau LSP) to analyze luau code.
Many lua game engines, such as defold or love2d, use global functions as callbacks for user scripts.
For instance, in defold, this global function will be called in every frame
function update(self, dt)
end
As a developer of a game that uses Luau for behavior scripts (and mod support), it would be very helpful for development to be able to specify these callback functions, with the following benefits:
- Autocomplete callback names and signatures
- Check if the signature is valid
- Automatically add documentation to the callback function
Currently, declaring the function using a function declaration results in an error indicating that global functions cannot be overridden.
declare function update(self: GameObject, dt: number)
I think the current behavior is correct. Such declarations are for functions that are available globally.
However, I propose the following potential syntaxes for "callback" declarations:
declare callback update(self: GameObject, dt: number)
declare abstract function update(self: GameObject, dt: number)
declare override function update(self: GameObject, dt: number)
I don't have a particular preference for any syntax as long as the feature can be implemented. Additionally, I can volunteer my time in order to add such a feature, but I wanted to check if this would be accepted first before actually sending a PR.