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
This commit is contained in:
ZyX
2016-03-04 21:55:28 +03:00
parent f9a31e9850
commit e7bbd8256b
11 changed files with 1100 additions and 14 deletions

View File

@@ -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
*/