diff options
author | ZyX <kp-pav@yandex.ru> | 2017-01-29 19:51:55 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-27 00:12:42 +0300 |
commit | dcb992ab3759b604c1824913002714a018be0532 (patch) | |
tree | db7b6a205518c504685782e73df5b59ca06fd4cb /src/nvim/viml/executor/executor.c | |
parent | 295e7607c472b49e8c0762977e38c4527b746b6f (diff) | |
download | rneovim-dcb992ab3759b604c1824913002714a018be0532.tar.gz rneovim-dcb992ab3759b604c1824913002714a018be0532.tar.bz2 rneovim-dcb992ab3759b604c1824913002714a018be0532.zip |
executor: Add :luafile command
Diffstat (limited to 'src/nvim/viml/executor/executor.c')
-rw-r--r-- | src/nvim/viml/executor/executor.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/nvim/viml/executor/executor.c b/src/nvim/viml/executor/executor.c index df63667102..a01bf9966d 100644 --- a/src/nvim/viml/executor/executor.c +++ b/src/nvim/viml/executor/executor.c @@ -161,7 +161,7 @@ static int nlua_exec_luado_string(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { const String *const str = (const String *)lua_touserdata(lstate, 1); const linenr_T *const range = (const linenr_T *)lua_touserdata(lstate, 2); - lua_pop(lstate, 1); + lua_pop(lstate, 2); #define DOSTART "return function(line, linenr) " #define DOEND " end" @@ -225,6 +225,26 @@ static int nlua_exec_luado_string(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL return 0; } +/// Evaluate lua file +/// +/// Expects one value on the stack: file to evaluate. Always returns nothing +/// (from the lua point of view). +static int nlua_exec_lua_file(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL +{ + const char *const filename = (const char *)lua_touserdata(lstate, 1); + lua_pop(lstate, 1); + + if (luaL_loadfile(lstate, filename)) { + nlua_error(lstate, _("E5112: Error while creating lua chunk: %.*s")); + return 0; + } + if (lua_pcall(lstate, 0, 0, 0)) { + nlua_error(lstate, _("E5113: Error while calling lua chunk: %.*s")); + return 0; + } + return 0; +} + /// Initialize lua interpreter state /// /// Called by lua interpreter itself to initialize state. @@ -402,3 +422,18 @@ void ex_luado(exarg_T *const eap) NLUA_CALL_C_FUNCTION_2(global_lstate, nlua_exec_luado_string, 0, (void *)&cmd, (void *)range); } + +/// Run lua file +/// +/// Used for :luafile. +/// +/// @param eap VimL command being run. +void ex_luafile(exarg_T *const eap) + FUNC_ATTR_NONNULL_ALL +{ + if (global_lstate == NULL) { + global_lstate = init_lua(); + } + NLUA_CALL_C_FUNCTION_1(global_lstate, nlua_exec_lua_file, 0, + (void *)eap->arg); +} |