Repository navigation
fix(type): luajit coroutine.running() - #1027
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the version annotation for the coroutine.running function in the Lua standard library definitions to include JIT support for the Lua 5.1 signature. However, the review feedback points out that LuaJIT actually follows the Lua 5.2+ specification for this function, which returns two values rather than a single thread reference. To provide accurate type information, the JIT tag should be moved to the 5.2+ definition instead of being associated with the 5.1 version.
| function coroutine.resume(co, val1, ...) end | ||
|
|
||
| ---@version 5.1 | ||
| ---@version 5.1, JIT |
There was a problem hiding this comment.
In LuaJIT, coroutine.running() follows the Lua 5.2+ specification, returning two values: the running coroutine (which is the main thread rather than nil when called from the main thread) and a boolean indicating if it is the main thread.
By adding JIT to this definition, you are associating LuaJIT with the Lua 5.1 signature (returning a single thread? value). This provides incorrect type information for LuaJIT users.
To correctly resolve the version warning while providing accurate types, you should instead add JIT to the second definition of coroutine.running() at line 71 (e.g., ---@version > 5.2, JIT).
---@version 5.1
There was a problem hiding this comment.
This don't seem true.
~ master ❯ rlwrap luajit
LuaJIT 2.1.1774896198 -- Copyright (C) 2005-2026 Mike Pall. https://luajit.org/
JIT: ON SSE3 SSE4.1 BMI2 fold cse dce fwd dse narrow loop abc sink fuse
> =coroutine.wrap(coroutine.running)()
thread: 0x7f0655af85c8
~ master ❯ lua5.5
Lua 5.5.0 Copyright (C) 1994-2025 Lua.org, PUC-Rio
> =coroutine.wrap(coroutine.running)()
stdin:1: unexpected symbol near '='
> coroutine.wrap(coroutine.running)()
thread: 0x5650ae7ede28 false
>
It give warning "The current Lua version Lua JIT is not accessible; expected >= Lua 5.2."after debde573