@@ -8,6 +8,17 @@ use std::ptr::null_mut;
8
8
/// 2. lauxlib
9
9
/// 3. Lua utitlites, implemented in Tarantool
10
10
11
+ /// Lua provides a registry, a pre-defined table that can be used by any C code
12
+ /// to store whatever Lua value it needs to store. This table is always located
13
+ /// at pseudo-index `LUA_REGISTRYINDEX`. Any C library can store data into this
14
+ /// table, but it should take care to choose keys different from those used by
15
+ /// other libraries, to avoid collisions. Typically, you should use as key a
16
+ /// string containing your library name or a light userdata with the address of
17
+ /// a C object in your code.
18
+ ///
19
+ /// The integer keys in the registry are used by the reference mechanism,
20
+ /// implemented by the auxiliary library, and therefore should not be used for
21
+ /// other purposes.
11
22
pub const LUA_REGISTRYINDEX : c_int = -10000 ;
12
23
pub const LUA_ENVIRONINDEX : c_int = -10001 ;
13
24
pub const LUA_GLOBALSINDEX : c_int = -10002 ;
@@ -33,6 +44,9 @@ pub const LUA_TTHREAD: c_int = 8;
33
44
34
45
pub const LUA_MINSTACK : c_int = 20 ;
35
46
47
+ pub const LUA_NOREF : c_int = -2 ;
48
+ pub const LUA_REFNIL : c_int = -1 ;
49
+
36
50
#[ repr( C ) ]
37
51
#[ derive( Debug , Copy , Clone ) ]
38
52
pub struct lua_State {
@@ -321,6 +335,29 @@ extern "C" {
321
335
/// as return `luaL_error(args)`.
322
336
pub fn luaL_error ( l : * mut lua_State , fmt : * const c_schar , ...) -> c_int ;
323
337
pub fn luaL_openlibs ( L : * mut lua_State ) ;
338
+
339
+ /// Creates and returns a reference, in the table at index `t`, for the
340
+ /// object at the top of the stack (and pops the object).
341
+ /// *[-1, +0, m]*
342
+ ///
343
+ /// A reference is a unique integer key. As long as you do not manually add
344
+ /// integer keys into table t, `luaL_ref` ensures the uniqueness of the key
345
+ /// it returns. You can retrieve an object referred by reference r by
346
+ /// calling [`lua_rawgeti`]`(L, t, r)`. Function [`luaL_unref`] frees a
347
+ /// reference and its associated object.
348
+ ///
349
+ /// If the object at the top of the stack is nil, `luaL_ref` returns the
350
+ /// constant [`LUA_REFNIL`]. The constant [`LUA_NOREF`] is guaranteed to be
351
+ /// different from any reference returned by `luaL_ref`.
352
+ pub fn luaL_ref ( l : * mut lua_State , t : c_int ) -> c_int ;
353
+
354
+ /// Releases reference `r` from the table at index `t` (see [`luaL_ref`]).
355
+ /// The entry is removed from the table, so that the referred object can be
356
+ /// collected. The reference `r` is also freed to be used again.
357
+ /// *[-0, +0, -]*
358
+ ///
359
+ /// If ref is [`LUA_NOREF`] or [`LUA_REFNIL`], `luaL_unref` does nothing.
360
+ pub fn luaL_unref ( l : * mut lua_State , t : c_int , r : c_int ) ;
324
361
}
325
362
326
363
#[ inline( always) ]
0 commit comments