You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to define type hints for user callback functions #3371
I am working on a lua api for a C++ game. And users creating these plugins can implement global function that will be called by C++. I tried putting a few type hints into my meta file like these but it did not properly let me autocomplete function on_<tab>
changed the title [-]How to define type hints for functions in the global scope[/-][+]How to define type hints for user callback functions[/+]on Mar 8, 2026
I also figured out this works. But that requires my users to be deep into the type annotation game. That is not realistic. Or do love2d users for example actually actively do that in the wild?
Also it does not even autocomplete function love.up<tab> right? So users would have to know the full callback name and type name. If they match that is of course easier. But this means that users have to read the documentation or manually find the meta file somehow to be able to use a library. Because the language server is not giving support here.
I mean the project is really cool already and I take what I get I just assumed it could do that smoothly somehow.
But that requires my users to be deep into the type annotation game. That is not realistic.
Yes, and I agree with you.
Also it does not even autocomplete function love.up right?
Yep, because @alias only defines a type, not the global function.
You will only get the autocompletion when completing a type, eg ---@type love.up<tab> => it should show up
Because the language server is not giving support here.
I am just a user and contributor (fixed a few bugs) not maintainer. So I am not able to help further 🙈
I am just a user and contributor (fixed a few bugs) not maintainer. So I am not able to help further 🙈
You did good. Thanks for responding. I wanted to make sure I am not missing something and it looks like I did not. The issue was more of a question than a feature request. While I would love this feature I understand it might be tricky to realize. So if any maintainer sees this feel free to close the issue. I will leave it open for now with the hope of someone chipping in some other workaround.
@CppCXY so doing naked global functions does not work but members of a table do? I can change my api just to make that work :D just wanted to double check.
Okay I tested this it works really well. Amazing thanks @CppCXY !!!
Even the function name completes here function t.on_player_co<tab> sadly it does not complete the parameters with it :(
And I also wonder how to then give the parameters detailed descriptions but thats for another issue #3372.
Does that mean the LuaCATS/love2d annotations are wrong?
Ah yes I see. The alias can be useful if the user wants to annotate callbacks. But as far as I understand it love.update is mostly implemented by the user and rarely passed around as callback by the user. So my assumption stays that the LuaCATS/love2d annotations are wrong. Or at least not as good as they can be. Or not vibing with this language server 🤷
I kinda assumed that the love annotations were the gold standard.
Anyways this comment is exactly what I opened the issue for and it works great for me. Thanks!
Activity
ChillerDragon commentedon Mar 8, 2026
Hmm I had a look at how it is done for love2d and I could not get that to work either :/
I installed this https://github.com/LuaCATS/love2d/tree/main
And I get type hints for the functions the user can call just fine
But no type hints for the callbacks the user can define
Even tho they seem to be defined here
https://github.com/LuaCATS/love2d/blob/765abafe49775ba52937430e2546dfc330381d6b/library/love.lua#L319-L322
[-]How to define type hints for functions in the global scope[/-][+]How to define type hints for user callback functions[/+]Start to document hooks (not sure how yet)
tomlau10 commentedon Mar 9, 2026
AFAIK, the callback types are expected to be used like this
@aliasto define a function typeChillerDragon commentedon Mar 9, 2026
@tomlau10 oof :/ thanks for sharing that c:
I also figured out this works. But that requires my users to be deep into the type annotation game. That is not realistic. Or do love2d users for example actually actively do that in the wild?
Also it does not even autocomplete
function love.up<tab>right? So users would have to know the full callback name and type name. If they match that is of course easier. But this means that users have to read the documentation or manually find the meta file somehow to be able to use a library. Because the language server is not giving support here.I mean the project is really cool already and I take what I get I just assumed it could do that smoothly somehow.
tomlau10 commentedon Mar 9, 2026
Yes, and I agree with you.
Yep, because
@aliasonly defines a type, not the global function.You will only get the autocompletion when completing a type, eg
---@type love.up<tab>=> it should show upI am just a user and contributor (fixed a few bugs) not maintainer. So I am not able to help further 🙈
ChillerDragon commentedon Mar 9, 2026
You did good. Thanks for responding. I wanted to make sure I am not missing something and it looks like I did not. The issue was more of a question than a feature request. While I would love this feature I understand it might be tricky to realize. So if any maintainer sees this feel free to close the issue. I will leave it open for now with the hope of someone chipping in some other workaround.
CppCXY commentedon Mar 9, 2026
ChillerDragon commentedon Mar 9, 2026
Interesting how did
tget the type?UPDATE:
Ah wait I see it now :D
Okay let me test this real quick thanks.
ChillerDragon commentedon Mar 9, 2026
@CppCXY so doing naked global functions does not work but members of a table do? I can change my api just to make that work :D just wanted to double check.
ChillerDragon commentedon Mar 9, 2026
Okay I tested this it works really well. Amazing thanks @CppCXY !!!
Even the function name completes here
function t.on_player_co<tab>sadly it does not complete the parameters with it :(And I also wonder how to then give the parameters detailed descriptions but thats for another issue #3372.
Does that mean the LuaCATS/love2d annotations are wrong?
CppCXY commentedon Mar 9, 2026
that maybe mean a function param type:
ChillerDragon commentedon Mar 9, 2026
Ah yes I see. The alias can be useful if the user wants to annotate callbacks. But as far as I understand it
love.updateis mostly implemented by the user and rarely passed around as callback by the user. So my assumption stays that the LuaCATS/love2d annotations are wrong. Or at least not as good as they can be. Or not vibing with this language server 🤷I kinda assumed that the love annotations were the gold standard.
Anyways this comment is exactly what I opened the issue for and it works great for me. Thanks!