robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

bfredlfeat(api): nvim_buf_call, win_call can has multiple return values #398010aa7d2f4d5

master
2.2 KiB68 linesraw
1#pragma once
2
3#include <lauxlib.h>
4#include <lua.h>
5#include <stdbool.h>
6
7#include "nvim/api/private/defs.h"
8#include "nvim/api/private/helpers.h"
9#include "nvim/cmdexpand_defs.h"  // IWYU pragma: keep
10#include "nvim/ex_cmds_defs.h"  // IWYU pragma: keep
11#include "nvim/garray_defs.h"  // IWYU pragma: keep
12#include "nvim/macros_defs.h"
13#include "nvim/types_defs.h"
14#include "nvim/usercmd.h"  // IWYU pragma: keep
15
16// Generated by generators/gen_api_dispatch.lua
17void nlua_add_api_functions(lua_State *lstate) REAL_FATTR_NONNULL_ALL;
18
19typedef struct {
20  LuaRef nil_ref;
21  LuaRef empty_dict_ref;
22  int ref_count;
23#if __has_feature(address_sanitizer)
24  PMap(int) ref_markers;
25#endif
26} nlua_ref_state_t;
27
28#define NLUA_EXEC_STATIC(cstr, arg, mode, arena, err) \
29  nlua_exec(STATIC_CSTR_AS_STRING(cstr), NULL, arg, mode, arena, err)
30
31#define NLUA_CLEAR_REF(x) \
32  do { \
33    /* Take the address to avoid double evaluation. #1375 */ \
34    if ((x) != LUA_NOREF) { \
35      api_free_luaref(x); \
36      (x) = LUA_NOREF; \
37    } \
38  } while (0)
39
40typedef enum {
41  kRetObject,   ///< any object, but doesn't preserve nested luarefs
42  kRetNilBool,  ///< NIL preserved as such, other values return their booleanness
43                ///< Should also be used when return value is ignored, as it is allocation-free
44  kRetLuaref,   ///< return value becomes a single Luaref, regardless of type (except NIL)
45  kRetMulti,    ///< like kRetObject but return multiple return values as an Array
46  kRetMultiStack,  ///< like kRetMulti but leave values on the lua stack
47} LuaRetMode;
48
49/// Maximum number of errors in vim.ui_attach() and decor provider callbacks.
50enum { CB_MAX_ERROR = 3, };
51
52/// To use with kRetNilBool for quick truthiness check
53#define LUARET_TRUTHY(res) ((res).type == kObjectTypeBoolean && (res).data.boolean == true)
54
55#include "lua/executor.h.generated.h"
56
57EXTERN nlua_ref_state_t *nlua_global_refs INIT( = NULL);
58EXTERN bool nlua_disable_preload INIT( = false);
59
60/// Tracks the active Lua thread
61extern lua_State *active_lstate;
62
63#define ENTER_LUA_ACTIVE_STATE(new_state) \
64  lua_State *const save_active_lstate = active_lstate; \
65  active_lstate = (new_state);
66
67#define LEAVE_LUA_ACTIVE_STATE() \
68  active_lstate = save_active_lstate;