Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
executor.c File Reference
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <tree_sitter/api.h>
#include "luv/luv.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/buffer_defs.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/event/loop.h"
#include "nvim/event/time.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/lua/stdlib.h"
#include "nvim/lua/treesitter.h"
#include "nvim/macros.h"
#include "nvim/map.h"
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/os/os.h"
#include "nvim/screen.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/vim.h"

Data Structures

struct  LuaError
struct  ModuleDef


#define PUSH_ALL_TYPVALS(lstate, args, argcount, special)
#define PRINT_ERROR(msg)
#define EVALHEADER   "local _A=select(1,...) return ("
#define CALLHEADER   "return "
#define CALLSUFFIX   "(...)"
#define DOSTART   "return function(line, linenr) "
#define DOEND   " end"


typedef enum luv_err_type luv_err_t


enum  luv_err_type { kCallback, kThread, kThreadCallback }


static int lua_pushlightuserdata (lstate, ud)
LuaRef nlua_get_nil_ref (lua_State *lstate) FUNC_ATTR_NONNULL_ALL
LuaRef nlua_get_empty_dict_ref (lua_State *lstate) FUNC_ATTR_NONNULL_ALL
int nlua_get_global_ref_count (void)
void nlua_init (void)
void nlua_free_all_mem (void)
int nlua_in_fast_event (lua_State *lstate)
int nlua_call (lua_State *lstate)
LuaRef nlua_ref (lua_State *lstate, nlua_ref_state_t *ref_state, int index)
LuaRef nlua_ref_global (lua_State *lstate, int index)
void nlua_unref (lua_State *lstate, nlua_ref_state_t *ref_state, LuaRef ref)
 remove the value from the registry More...
void nlua_unref_global (lua_State *lstate, LuaRef ref)
void api_free_luaref (LuaRef ref)
void nlua_pushref (lua_State *lstate, LuaRef ref)
 push a value referenced in the registry More...
LuaRef api_new_luaref (LuaRef original_ref)
void nlua_typval_eval (const String str, typval_T *const arg, typval_T *const ret_tv) FUNC_ATTR_NONNULL_ALL
void nlua_typval_call (const char *str, size_t len, typval_T *const args, int argcount, typval_T *ret_tv) FUNC_ATTR_NONNULL_ALL
void nlua_call_user_expand_func (expand_T *xp, typval_T *ret_tv) FUNC_ATTR_NONNULL_ALL
int nlua_source_using_linegetter (LineGetter fgetline, void *cookie, char *name)
int typval_exec_lua_callable (lua_State *lstate, LuaCallable lua_cb, int argcount, typval_T *argvars, typval_T *rettv)
Object nlua_exec (const String str, const Array args, Error *err)
bool nlua_ref_is_function (LuaRef ref)
Object nlua_call_ref (LuaRef ref, const char *name, Array args, bool retval, Error *err)
bool nlua_is_deferred_safe (void)
void ex_lua (exarg_T *const eap) FUNC_ATTR_NONNULL_ALL
void ex_luado (exarg_T *const eap) FUNC_ATTR_NONNULL_ALL
void ex_luafile (exarg_T *const eap) FUNC_ATTR_NONNULL_ALL
bool nlua_exec_file (const char *path) FUNC_ATTR_NONNULL_ALL
int tslua_get_language_version (lua_State *L)
int tslua_get_minimum_language_version (lua_State *L)
int nlua_expand_pat (expand_T *xp, char_u *pat, int *num_results, char_u ***results)
int nlua_CFunction_func_call (int argcount, typval_T *argvars, typval_T *rettv, void *state)
void nlua_CFunction_func_free (void *state)
bool nlua_is_table_from_lua (typval_T *const arg)
char_unlua_register_table_as_callable (typval_T *const arg)
void nlua_execute_on_key (int c)
void nlua_set_sctx (sctx_T *current)
void nlua_do_ucmd (ucmd_T *cmd, exarg_T *eap)


int retval = nlua_luv_thread_cfpcall(lstate, 1, 0, flags)

Macro Definition Documentation


#define CALLHEADER   "return "


#define CALLSUFFIX   "(...)"


#define DOEND   " end"


#define DOSTART   "return function(line, linenr) "


#define EVALHEADER   "local _A=select(1,...) return ("


#define PRINT_ERROR (   msg)
do { \
errmsg = msg; \
errmsg_len = sizeof(msg) - 1; \
goto nlua_print_error; \
} while (0)


#define PUSH_ALL_TYPVALS (   lstate,
for (int i = 0; i < argcount; i++) { \
if (args[i].v_type == VAR_UNKNOWN) { \
lua_pushnil(lstate); \
} else { \
nlua_push_typval(lstate, &args[i], special); \
} \

Typedef Documentation

◆ luv_err_t

typedef enum luv_err_type luv_err_t

Enumeration Type Documentation

◆ luv_err_type


Function Documentation

◆ api_free_luaref()

void api_free_luaref ( LuaRef  ref)

◆ api_new_luaref()

LuaRef api_new_luaref ( LuaRef  original_ref)

Gets a new reference to an object stored at original_ref

NOTE: It does not copy the value, it creates a new ref to the lua object. Leaves the stack unchanged.

◆ ex_lua()

void ex_lua ( exarg_T *const  eap)

Run lua string

Used for :lua.

eapVimL command being run.

◆ ex_luado()

void ex_luado ( exarg_T *const  eap)

Run lua string for each line in range

Used for :luado.

eapVimL command being run.

◆ ex_luafile()

void ex_luafile ( exarg_T *const  eap)

Run lua file

Used for :luafile.

eapVimL command being run.

◆ lua_pushlightuserdata()

static int lua_pushlightuserdata ( lstate  ,

◆ nlua_call()

int nlua_call ( lua_State *  lstate)

◆ nlua_call_ref()

Object nlua_call_ref ( LuaRef  ref,
const char *  name,
Array  args,
bool  retval,
Error err 

call a LuaRef as a function (or table with __call metamethod)

refthe reference to call (not consumed)
nameif non-NULL, sent to callback as first arg if NULL, only args are used
retvalif true, convert return value to Object if false, discard return value
errError details, if any (if NULL, errors are echoed)
Return value of function, if retval was set. Otherwise NIL.

◆ nlua_call_user_expand_func()

void nlua_call_user_expand_func ( expand_T xp,
typval_T ret_tv 

◆ nlua_CFunction_func_call()

int nlua_CFunction_func_call ( int  argcount,
typval_T argvars,
typval_T rettv,
void state 

◆ nlua_CFunction_func_free()

void nlua_CFunction_func_free ( void state)

◆ nlua_do_ucmd()

void nlua_do_ucmd ( ucmd_T cmd,
exarg_T eap 

◆ nlua_exec()

Object nlua_exec ( const String  str,
const Array  args,
Error err 

Execute Lua string

Used for nvim_exec_lua() and internally to execute a lua string.

[in]strString to execute.
[in]argsarray of ... args
[out]errLocation where error will be saved.
Return value of the execution.

◆ nlua_exec_file()

bool nlua_exec_file ( const char *  path)

execute lua code from a file.

Note: we call the lua global loadfile as opposed to calling luaL_loadfile in case loadfile has been overridden in the users environment.

pathpath of the file
true if everything ok, false if there was an error (echoed)

◆ nlua_execute_on_key()

void nlua_execute_on_key ( int  c)

◆ nlua_expand_pat()

int nlua_expand_pat ( expand_T xp,
char_u pat,
int *  num_results,
char_u ***  results 

◆ nlua_free_all_mem()

void nlua_free_all_mem ( void  )

◆ nlua_get_empty_dict_ref()

LuaRef nlua_get_empty_dict_ref ( lua_State *  lstate)

◆ nlua_get_global_ref_count()

int nlua_get_global_ref_count ( void  )

◆ nlua_get_nil_ref()

LuaRef nlua_get_nil_ref ( lua_State *  lstate)

◆ nlua_in_fast_event()

int nlua_in_fast_event ( lua_State *  lstate)

◆ nlua_init()

void nlua_init ( void  )

Initialize global lua interpreter

Crashes Nvim if initialization fails.

◆ nlua_is_deferred_safe()

bool nlua_is_deferred_safe ( void  )

check if the current execution context is safe for calling deferred API methods. Luv callbacks are unsafe as they are called inside the uv loop.

◆ nlua_is_table_from_lua()

bool nlua_is_table_from_lua ( typval_T *const  arg)

◆ nlua_pushref()

void nlua_pushref ( lua_State *  lstate,
LuaRef  ref 

push a value referenced in the registry

◆ nlua_ref()

LuaRef nlua_ref ( lua_State *  lstate,
nlua_ref_state_t ref_state,
int  index 

add the value to the registry The current implementation does not support calls from threads.

◆ nlua_ref_global()

LuaRef nlua_ref_global ( lua_State *  lstate,
int  index 

◆ nlua_ref_is_function()

bool nlua_ref_is_function ( LuaRef  ref)

◆ nlua_register_table_as_callable()

char_u* nlua_register_table_as_callable ( typval_T *const  arg)

◆ nlua_set_sctx()

void nlua_set_sctx ( sctx_T current)

◆ nlua_source_using_linegetter()

int nlua_source_using_linegetter ( LineGetter  fgetline,
void cookie,
char *  name 

◆ nlua_typval_call()

void nlua_typval_call ( const char *  str,
size_t  len,
typval_T *const  args,
int  argcount,
typval_T ret_tv 

◆ nlua_typval_eval()

void nlua_typval_eval ( const String  str,
typval_T *const  arg,
typval_T *const  ret_tv 

Evaluate lua string

Used for luaeval().

[in]strString to execute.
[in]argSecond argument to luaeval().
[out]ret_tvLocation where result will be saved.
Result of the execution.

◆ nlua_unref()

void nlua_unref ( lua_State *  lstate,
nlua_ref_state_t ref_state,
LuaRef  ref 

remove the value from the registry

◆ nlua_unref_global()

void nlua_unref_global ( lua_State *  lstate,
LuaRef  ref 

◆ tslua_get_language_version()

int tslua_get_language_version ( lua_State *  L)

◆ tslua_get_minimum_language_version()

int tslua_get_minimum_language_version ( lua_State *  L)

◆ typval_exec_lua_callable()

int typval_exec_lua_callable ( lua_State *  lstate,
LuaCallable  lua_cb,
int  argcount,
typval_T argvars,
typval_T rettv 

Call a LuaCallable given some typvals

Used to call any lua callable passed from Lua into VimL

[in]lstateLua State
[in]lua_cbLua Callable
[in]argcountCount of typval arguments
[in]argvarsTypval Arguments
[out]rettvThe return value from the called function.

Variable Documentation

◆ retval

return retval = nlua_luv_thread_cfpcall(lstate, 1, 0, flags)
static void int i
Definition: edit.c:3047
Unknown (unspecified) value.
Definition: typval.h:120
err msg
Definition: helpers.c:1110
void argv[0] v_type
Definition: typval.c:1286
va_list args
Definition: log.c:149