(libretrodb) lua_common.c - buildfix
This commit is contained in:
parent
78185be8bf
commit
cb9af706d1
|
@ -16,13 +16,13 @@ int libretrodb_lua_to_rmsgpack_value(lua_State * L, int index, struct rmsgpack_d
|
||||||
const int MAX_FIELDS = 100;
|
const int MAX_FIELDS = 100;
|
||||||
|
|
||||||
out->type = RDT_MAP;
|
out->type = RDT_MAP;
|
||||||
out->map.len = 0;
|
out->val.map.len = 0;
|
||||||
out->map.items = calloc(MAX_FIELDS, sizeof(struct rmsgpack_dom_pair));
|
out->val.map.items = calloc(MAX_FIELDS, sizeof(struct rmsgpack_dom_pair));
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
|
||||||
while (lua_next(L, index - 1) != 0)
|
while (lua_next(L, index - 1) != 0)
|
||||||
{
|
{
|
||||||
if (out->map.len > MAX_FIELDS)
|
if (out->val.map.len > MAX_FIELDS)
|
||||||
printf("skipping due to too many keys\n");
|
printf("skipping due to too many keys\n");
|
||||||
else if (!lua_isstring(L, key_idx))
|
else if (!lua_isstring(L, key_idx))
|
||||||
printf("skipping non string key\n");
|
printf("skipping non string key\n");
|
||||||
|
@ -32,29 +32,29 @@ int libretrodb_lua_to_rmsgpack_value(lua_State * L, int index, struct rmsgpack_d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = out->map.len;
|
i = out->val.map.len;
|
||||||
tmp_buff = strdup(lua_tostring(L, key_idx));
|
tmp_buff = strdup(lua_tostring(L, key_idx));
|
||||||
out->map.items[i].key.type = RDT_STRING;
|
out->val.map.items[i].key.type = RDT_STRING;
|
||||||
out->map.items[i].key.string.len = strlen(tmp_buff);
|
out->val.map.items[i].key.val.string.len = strlen(tmp_buff);
|
||||||
out->map.items[i].key.string.buff = tmp_buff;
|
out->val.map.items[i].key.val.string.buff = tmp_buff;
|
||||||
|
|
||||||
tmp_value = &out->map.items[i].value;
|
tmp_value = &out->val.map.items[i].value;
|
||||||
switch (lua_type(L, value_idx))
|
switch (lua_type(L, value_idx))
|
||||||
{
|
{
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
tmp_num = lua_tonumber(L, value_idx);
|
tmp_num = lua_tonumber(L, value_idx);
|
||||||
tmp_value->type = RDT_INT;
|
tmp_value->type = RDT_INT;
|
||||||
tmp_value->int_ = tmp_num;
|
tmp_value->val.int_ = tmp_num;
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
tmp_value->type = RDT_BOOL;
|
tmp_value->type = RDT_BOOL;
|
||||||
tmp_value->bool_ = lua_toboolean(L, value_idx);
|
tmp_value->val.bool_ = lua_toboolean(L, value_idx);
|
||||||
break;
|
break;
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
tmp_buff = strdup(lua_tostring(L, value_idx));
|
tmp_buff = strdup(lua_tostring(L, value_idx));
|
||||||
tmp_value->type = RDT_STRING;
|
tmp_value->type = RDT_STRING;
|
||||||
tmp_value->string.len = strlen(tmp_buff);
|
tmp_value->val.string.len = strlen(tmp_buff);
|
||||||
tmp_value->string.buff = tmp_buff;
|
tmp_value->val.string.buff = tmp_buff;
|
||||||
break;
|
break;
|
||||||
case LUA_TTABLE:
|
case LUA_TTABLE:
|
||||||
lua_getfield(L, value_idx, "binary");
|
lua_getfield(L, value_idx, "binary");
|
||||||
|
@ -71,7 +71,7 @@ int libretrodb_lua_to_rmsgpack_value(lua_State * L, int index, struct rmsgpack_d
|
||||||
{
|
{
|
||||||
tmp_num = lua_tonumber(L, -1);
|
tmp_num = lua_tonumber(L, -1);
|
||||||
tmp_value->type = RDT_UINT;
|
tmp_value->type = RDT_UINT;
|
||||||
tmp_value->uint_ = tmp_num;
|
tmp_value->val.uint_ = tmp_num;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,8 @@ int libretrodb_lua_to_rmsgpack_value(lua_State * L, int index, struct rmsgpack_d
|
||||||
tmp_buff = malloc(tmp_len);
|
tmp_buff = malloc(tmp_len);
|
||||||
memcpy(tmp_buff, tmp_string, tmp_len);
|
memcpy(tmp_buff, tmp_string, tmp_len);
|
||||||
tmp_value->type = RDT_BINARY;
|
tmp_value->type = RDT_BINARY;
|
||||||
tmp_value->binary.len = tmp_len;
|
tmp_value->val.binary.len = tmp_len;
|
||||||
tmp_value->binary.buff = tmp_buff;
|
tmp_value->val.binary.buff = tmp_buff;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -90,7 +90,7 @@ int libretrodb_lua_to_rmsgpack_value(lua_State * L, int index, struct rmsgpack_d
|
||||||
set_nil:
|
set_nil:
|
||||||
tmp_value->type = RDT_NULL;
|
tmp_value->type = RDT_NULL;
|
||||||
}
|
}
|
||||||
out->map.len++;
|
out->val.map.len++;
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue