Skip to content

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

@b0mbie

Description

@b0mbie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions