lua: add vim.fn.{func} for direct access to vimL function

compared to vim.api.|nvim_call_function|, this fixes some typing issues
due to the indirect conversion via the API. float values are preserved
as such (fixes #9389) as well as empty dicts/arrays.

Ref https://github.com/norcalli/nvim.lua for the call syntax
This commit is contained in:
Björn Linse
2019-08-25 22:01:35 +02:00
parent 19ba36d0e1
commit 8ee7c94a92
5 changed files with 130 additions and 3 deletions

View File

@@ -401,6 +401,8 @@ nlua_pop_typval_table_processing_end:
return ret;
}
static bool typval_conv_special = false;
#define TYPVAL_ENCODE_ALLOW_SPECIALS true
#define TYPVAL_ENCODE_CONV_NIL(tv) \
@@ -439,7 +441,13 @@ nlua_pop_typval_table_processing_end:
lua_createtable(lstate, 0, 0)
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict) \
nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary)
do { \
if (typval_conv_special) { \
nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary); \
} else { \
lua_createtable(lstate, 0, 0); \
} \
} while (0)
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len) \
do { \
@@ -548,9 +556,11 @@ nlua_pop_typval_table_processing_end:
/// @param[in] tv typval_T to convert.
///
/// @return true in case of success, false otherwise.
bool nlua_push_typval(lua_State *lstate, typval_T *const tv)
bool nlua_push_typval(lua_State *lstate, typval_T *const tv, bool special)
{
typval_conv_special = special;
const int initial_size = lua_gettop(lstate);
if (!lua_checkstack(lstate, initial_size + 2)) {
emsgf(_("E1502: Lua failed to grow stack to %i"), initial_size + 4);
return false;