diff options
author | ZyX <kp-pav@yandex.ru> | 2016-03-04 21:55:28 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-27 00:11:24 +0300 |
commit | e7bbd8256b8c701205389be431bbafd8743c72a9 (patch) | |
tree | 9fc9a9754da4d856b94f8388ff700a01711dfe68 /src/nvim/eval.c | |
parent | f9a31e98505c0f5e83dd3ba957fbd0f4b150d30c (diff) | |
download | rneovim-e7bbd8256b8c701205389be431bbafd8743c72a9.tar.gz rneovim-e7bbd8256b8c701205389be431bbafd8743c72a9.tar.bz2 rneovim-e7bbd8256b8c701205389be431bbafd8743c72a9.zip |
eval: Add luaeval function
No tests yet, no documentation update, no :lua* stuff, no vim module.
converter.c should also work with typval_T, not Object.
Known problem: luaeval("1", {}) results in
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
Ref #3823
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d49fcbf17e..c9141fbcbf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -95,6 +95,7 @@ #include "nvim/lib/khash.h" #include "nvim/lib/queue.h" #include "nvim/eval/typval_encode.h" +#include "nvim/viml/executor/executor.h" #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ @@ -13376,6 +13377,48 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) } } +/// luaeval() function implementation +static void f_luaeval(typval_T *argvars, typval_T *rettv, FunPtr fptr) + FUNC_ATTR_NONNULL_ALL +{ + char *const str = (char *) get_tv_string(&argvars[0]); + if (str == NULL) { + return; + } + + Object arg; + if (argvars[1].v_type == VAR_UNKNOWN) { + arg = NIL; + } else { + arg = vim_to_object(&argvars[1]); + } + + // TODO(ZyX-I): Create function which converts lua objects directly to VimL + // objects, not to API objects. + Error err; + String err_str; + Object ret = executor_eval_lua(cstr_as_string(str), arg, &err, &err_str); + if (err.set) { + if (err_str.size) { + EMSG3(_("E971: Failed to eval lua string: %s (%s)"), err.msg, + err_str.data); + } else { + EMSG2(_("E971: Failed to eval lua string: %s"), err.msg); + } + } + + api_free_string(err_str); + + if (!err.set) { + if (!object_to_vim(ret, rettv, &err)) { + EMSG2(_("E972: Failed to convert resulting API object to VimL: %s"), + err.msg); + } + } + + api_free_object(ret); +} + /* * "map()" function */ |