neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

executor.h (2160B)


      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
     17 void nlua_add_api_functions(lua_State *lstate) REAL_FATTR_NONNULL_ALL;
     18 
     19 typedef 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 
     40 typedef 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 } LuaRetMode;
     47 
     48 /// Maximum number of errors in vim.ui_attach() and decor provider callbacks.
     49 enum { CB_MAX_ERROR = 3, };
     50 
     51 /// To use with kRetNilBool for quick truthiness check
     52 #define LUARET_TRUTHY(res) ((res).type == kObjectTypeBoolean && (res).data.boolean == true)
     53 
     54 #include "lua/executor.h.generated.h"
     55 
     56 EXTERN nlua_ref_state_t *nlua_global_refs INIT( = NULL);
     57 EXTERN bool nlua_disable_preload INIT( = false);
     58 
     59 /// Tracks the active Lua thread
     60 extern lua_State *active_lstate;
     61 
     62 #define ENTER_LUA_ACTIVE_STATE(new_state) \
     63  lua_State *const save_active_lstate = active_lstate; \
     64  active_lstate = (new_state);
     65 
     66 #define LEAVE_LUA_ACTIVE_STATE() \
     67  active_lstate = save_active_lstate;