Skip to content

Commit 17da081

Browse files
committed
chore: add more luajit annotations from https://github.com/openresty/luajit2
1 parent 20912f9 commit 17da081

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

meta/3rd/OpenResty/library/jit.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---@meta
2+
3+
4+
--- Returns (and optionally sets) the current PRNG state (an array of 8 Lua
5+
--- numbers with 32-bit integer values) currently used by the JIT compiler.
6+
---
7+
--- When the `state` argument is non-nil, it is expected to be an array of up to 8
8+
--- unsigned Lua numbers, each with value less than 2\*\*32-1. This will set the
9+
--- current PRNG state and return the state that was overridden.
10+
---
11+
--- **Note:** For backward compatibility, `state` argument can also be an unsigned
12+
--- Lua number less than 2\*\*32-1.
13+
---
14+
--- **Note:** When the `state` argument is an array and less than 8 numbers, or the
15+
--- `state` is a number, the remaining positions are filled with zeros.
16+
---
17+
--- Usage:
18+
---
19+
--- ```lua
20+
--- local state = jit.prngstate()
21+
--- local oldstate = jit.prngstate{ a, b, c, ... }
22+
---
23+
--- jit.prngstate(32) -- {32, 0, 0, 0, 0, 0, 0, 0}
24+
--- jit.prngstate{432, 23, 50} -- {432, 23, 50, 0, 0, 0, 0, 0}
25+
--- ```
26+
---
27+
--- **Note:** This API has no effect if LuaJIT is compiled with
28+
--- `-DLUAJIT_DISABLE_JIT`, and will return a table with all `0`.
29+
---
30+
---@param state? integer[]
31+
---@return integer[] state
32+
function jit.prngstate(state) end
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
11
---@meta
2-
function thread_exdata() end
3-
return thread_exdata
2+
3+
--- **syntax:** *exdata = th_exdata(data?)*
4+
---
5+
--- This API allows for embedding user data into a thread (`lua_State`).
6+
---
7+
--- The retrieved `exdata` value on the Lua land is represented as a cdata object
8+
--- of the ctype `void*`.
9+
---
10+
--- As of this version, retrieving the `exdata` (i.e. `th_exdata()` without any
11+
--- argument) can be JIT compiled.
12+
---
13+
--- Usage:
14+
---
15+
--- ```lua
16+
--- local th_exdata = require "thread.exdata"
17+
---
18+
--- th_exdata(0xdeadbeefLL) -- set the exdata of the current Lua thread
19+
--- local exdata = th_exdata() -- fetch the exdata of the current Lua thread
20+
--- ```
21+
---
22+
--- Also available are the following public C API functions for manipulating
23+
--- `exdata` on the C land:
24+
---
25+
--- ```C
26+
--- void lua_setexdata(lua_State *L, void *exdata);
27+
--- void *lua_getexdata(lua_State *L);
28+
--- ```
29+
---
30+
--- The `exdata` pointer is initialized to `NULL` when the main thread is created.
31+
--- Any child Lua thread will inherit its parent's `exdata`, but still can override
32+
--- it.
33+
---
34+
--- **Note:** This API will not be available if LuaJIT is compiled with
35+
--- `-DLUAJIT_DISABLE_FFI`.
36+
---
37+
--- **Note bis:** This API is used internally by the OpenResty core, and it is
38+
--- strongly discouraged to use it yourself in the context of OpenResty.
39+
---@param data? any
40+
---@return any? data
41+
local function exdata(data) end
42+
43+
return exdata
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---@meta
2+
3+
--- Similar to `thread.exdata` but for a 2nd separate user data as a pointer value.
4+
---@param data? any
5+
---@return any? data
6+
local function exdata2(data) end
7+
8+
return exdata2

0 commit comments

Comments
 (0)