Skip to content
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

Overload hook.Add's eventName with events defined in the wiki #39

Open
b0mbie opened this issue Jan 17, 2024 · 1 comment
Open

Overload hook.Add's eventName with events defined in the wiki #39

b0mbie opened this issue Jan 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@b0mbie
Copy link
Contributor

b0mbie commented Jan 17, 2024

I don't know how much this is needed, but I think that having this would be a huge help while programming.

The page for hook.Add describes eventName like this:

The event to hook on to. This can be any GM hook, gameevent after using gameevent.Listen, or custom hook run with hook.Call or hook.Run.

LuaLS allows to specify a string as its own separate type.

So, if we take the GM:Move hook as an example, the hook.Add function can have an overload like:

--- @overload fun(eventName: "Move", identifier: any, func: fun(ply: Player, mv: CMoveData): boolean?)

... which will then allow for this to happen:
image
image
ply and mv will also be of the right types already, though LuaLS will complain if nothing is returned here, which may not be wanted if, for example, the programmer wants to just inspect ply and/or mv.
This can be accounted for by having the return type be optional here (boolean?).

Custom hooks should not be affected, as LuaLS will just use the original definition of the function, where eventName is string and func is simply function.

Adding GM hooks would be okay, but there's also the hooks described on the page for gameevent, which would require more special treatment.

@luttje luttje added the enhancement New feature or request label Jan 17, 2024
@luttje
Copy link
Owner

luttje commented Jan 17, 2024

This would be super useful I imagine!

We already track all these GM functions and their parameters and return types, so we could use that in creating an overload list to place above hook.Add.

You're on a roll finding great usability improvements. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants