feat(api, lua): support converting nested Funcref back to LuaRef (#17749)

This commit is contained in:
zeertzjq
2022-03-18 03:21:47 +08:00
committed by GitHub
parent 09a3b33d36
commit cac90d2de7
3 changed files with 95 additions and 36 deletions

View File

@@ -476,7 +476,13 @@ static bool typval_conv_special = false;
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
do { \
TYPVAL_ENCODE_CONV_NIL(tv); \
ufunc_T *fp = find_func(fun); \
assert(fp != NULL); \
if (fp->uf_cb == nlua_CFunction_func_call) { \
nlua_pushref(lstate, ((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
} else { \
TYPVAL_ENCODE_CONV_NIL(tv); \
} \
goto typval_encode_stop_converting_one_item; \
} while (0)
@@ -615,14 +621,6 @@ bool nlua_push_typval(lua_State *lstate, typval_T *const tv, bool special)
semsg(_("E1502: Lua failed to grow stack to %i"), initial_size + 4);
return false;
}
if (tv->v_type == VAR_FUNC) {
ufunc_T *fp = find_func(tv->vval.v_string);
assert(fp != NULL);
if (fp->uf_cb == nlua_CFunction_func_call) {
nlua_pushref(lstate, ((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref);
return true;
}
}
if (encode_vim_to_lua(lstate, tv, "nlua_push_typval argument") == FAIL) {
return false;
}