diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-21 13:55:12 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-10-03 10:46:57 +0200 |
commit | 32565922efe0d1a6e8e4dddb23295d1a08670b54 (patch) | |
tree | 501dd50b3ae199e3b52071d66d307e9d69772f82 /src/nvim/lua | |
parent | 9337fff8aad610acd5ef619f757686c47f0c118c (diff) | |
download | rneovim-32565922efe0d1a6e8e4dddb23295d1a08670b54.tar.gz rneovim-32565922efe0d1a6e8e4dddb23295d1a08670b54.tar.bz2 rneovim-32565922efe0d1a6e8e4dddb23295d1a08670b54.zip |
refactor(api): handle option dicts properly
Do not copy a lot of lua strings (dict keys) to just strequal() them
Just compare them directly to a dedicated hash function.
feat(generators): HASHY McHASHFACE
Diffstat (limited to 'src/nvim/lua')
-rw-r--r-- | src/nvim/lua/converter.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index fac5bab664..fd4cfc4c31 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -1299,3 +1299,25 @@ void nlua_init_types(lua_State *const lstate) lua_rawset(lstate, -3); } + + +void nlua_pop_keydict(lua_State *L, void *retval, field_hash hashy, Error *err) +{ + lua_pushnil(L); // [dict, nil] + while (lua_next(L, -2)) { + // [dict, key, value] + size_t len; + const char *s = lua_tolstring(L, -2, &len); + Object *field = hashy(retval, s, len); + if (!field) { + api_set_error(err, kErrorTypeValidation, "invalid key: %.*s", (int)len, s); + lua_pop(L, 3); // [] + return; + } + + *field = nlua_pop_Object(L, true, err); + } + // [dict] + lua_pop(L, 1); + // [] +} |