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
Question: How to document an array of functions which have a return type? #3370
I apologise if this is the wrong place, or this is documented somewhere. I've looked through the documentation website, and the Github issues on this repo and not found anything. But feel free to redirect me :).
I have a third party field which I need to set in multiple places, but it doesn't provide an insert-esque function so I'm writing a function which takes an array of functions as callbacks so it can all be done in one place, I've attached the idea if that is helpful at all.
But the bottom line is, I want to document that array of functions appropriately. This is the type signature I would expect in other languages:
(Key, is the return type of each function in my array).
Java
: ArrayList<Function<Wezterm, Key>>
Rust (in a language-nuance free world)
: Vec<Fn(Wezterm) -> Key>
(I'm by no means a lua expert, so this might sound completely insane, if there is a better way that jumps out you screaming, then by all means feel free to share lol)
---@classKeyslocalmodule= {}
------@classKeys.config---@fieldleader_setup_functionfun(): LeaderKey---@fieldsetup_functions{ fun(wezterm: Wezterm): Key } []local_= {}
---TODO---@paramweztermWezterm---@paramconfigConfig---@paramkey_configKeys.configfunctionmodule.setup(wezterm, config, key_config)
config.leader=key_config.leader_setup_function()
---The keys we're creating mappings for------This array has an insert function, using table.insert even though arrays don't have an insert for some reason---@typeKey[]localkeys= { insert=table.insert }
for_, funinpairs(key_config.setup_functions) dofun(wezterm)
endend---comment---@paramkeystring---@parammodsstring---@returnfun(): LeaderKeyfunctionmodule.leader(key, mods)
returnfunction()
return {
key=key,
mods=mods
}
endend
I've put this down as documentation, because I would expect this to be supported, and I couldn't find it in the documentation. Implying a gap (or me being blind), apologies if incorrectly tagged.
{ fun(wezterm: Wezterm): Key } [] is invalid ❌
because a table is defined with key-value { k: v }
{ [integer]: fun(wezterm: Wezterm): Key } works ✅
because it means a table with integer as index => function
which is similar to array
Type[] is actually a syntactic surgar for { [integer]: Type } IIUC
therefore { [integer]: fun(wezterm: Wezterm): Key }[] is totally different thing ❌
it means array of table where each integer index is a function
=> 2d array
Activity
tomlau10 commentedon Mar 9, 2026
You are very close to the correct annotation 🙈 just used the wrong bracket
it should be:
more explanations
{}is for table / object definition{ fun(wezterm: Wezterm): Key } []is invalid ❌because a table is defined with key-value
{ k: v }{ [integer]: fun(wezterm: Wezterm): Key }works ✅because it means a table with integer as index => function
which is similar to array
Type[]is actually a syntactic surgar for{ [integer]: Type }IIUC{ [integer]: fun(wezterm: Wezterm): Key }[]is totally different thing ❌it means array of table where each integer index is a function
=> 2d array
Eyrim commentedon Mar 9, 2026
That makes so much sense, thank you! I really appreciate it :)