aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/converter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/lua/converter.c')
-rw-r--r--src/nvim/lua/converter.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 07c53299fa..ca3c4f604a 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -755,7 +755,7 @@ void nlua_push_Array(lua_State *lstate, const Array array, bool special)
FUNC_ATTR_NONNULL_ALL \
{ \
lua_pushnumber(lstate, (lua_Number)(item)); \
-}
+ }
GENERATE_INDEX_FUNCTION(Buffer)
GENERATE_INDEX_FUNCTION(Window)
@@ -1126,9 +1126,9 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
size_t len;
const char *s = lua_tolstring(lstate, -1, &len);
*cur.obj = STRING_OBJ(((String) {
- .data = xmemdupz(s, len),
- .size = len,
- }));
+ .data = xmemdupz(s, len),
+ .size = len,
+ }));
break;
}
case LUA_TNUMBER: {
@@ -1147,10 +1147,10 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
switch (table_props.type) {
case kObjectTypeArray:
*cur.obj = ARRAY_OBJ(((Array) {
- .items = NULL,
- .size = 0,
- .capacity = 0,
- }));
+ .items = NULL,
+ .size = 0,
+ .capacity = 0,
+ }));
if (table_props.maxidx != 0) {
cur.obj->data.array.items =
xcalloc(table_props.maxidx,
@@ -1162,10 +1162,10 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
break;
case kObjectTypeDictionary:
*cur.obj = DICTIONARY_OBJ(((Dictionary) {
- .items = NULL,
- .size = 0,
- .capacity = 0,
- }));
+ .items = NULL,
+ .size = 0,
+ .capacity = 0,
+ }));
if (table_props.string_keys_num != 0) {
cur.obj->data.dictionary.items =
xcalloc(table_props.string_keys_num,
@@ -1299,3 +1299,31 @@ 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)
+{
+ if (!lua_istable(L, -1)) {
+ api_set_error(err, kErrorTypeValidation, "Expected lua table");
+ lua_pop(L, -1);
+ return;
+ }
+
+ 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);
+ // []
+}