(libretro-db) Style nits

This commit is contained in:
twinaphex 2015-09-17 07:11:49 +02:00
parent aa1405fab9
commit 16864b34f4
1 changed files with 90 additions and 83 deletions

View File

@ -3,35 +3,35 @@
#include <stdlib.h>
#include <string.h>
int libretrodb_lua_to_rmsgpack_value(
lua_State * L,
int index,
struct rmsgpack_dom_value * out
) {
int rv = -1;
int i;
int libretrodb_lua_to_rmsgpack_value(lua_State *L, int index,
struct rmsgpack_dom_value * out)
{
size_t tmp_len;
lua_Number tmp_num;
struct rmsgpack_dom_value * tmp_value;
int i, rv = -1;
const char * tmp_string = NULL;
char * tmp_buff = NULL;
struct rmsgpack_dom_value * tmp_value;
const int key_idx = -2;
const int value_idx = -1;
const int MAX_FIELDS = 100;
size_t tmp_len;
lua_Number tmp_num;
out->type = RDT_MAP;
out->val.map.len = 0;
out->val.map.items = calloc(MAX_FIELDS, sizeof(struct rmsgpack_dom_pair));
lua_pushnil(L);
while (lua_next(L, index - 1) != 0) {
if (out->val.map.len > MAX_FIELDS) {
while (lua_next(L, index - 1) != 0)
{
if (out->val.map.len > MAX_FIELDS)
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");
} else if (lua_isnil(L, value_idx)) {
else if (lua_isnil(L, value_idx))
{
// Skipping nil value fields to save disk space
} else {
}
else
{
i = out->val.map.len;
tmp_buff = strdup(lua_tostring(L, key_idx));
out->val.map.items[i].key.type = RDT_STRING;
@ -39,7 +39,8 @@ int libretrodb_lua_to_rmsgpack_value(
out->val.map.items[i].key.val.string.buff = tmp_buff;
tmp_value = &out->val.map.items[i].value;
switch (lua_type(L, value_idx)) {
switch (lua_type(L, value_idx))
{
case LUA_TNUMBER:
tmp_num = lua_tonumber(L, value_idx);
tmp_value->type = RDT_INT;
@ -57,19 +58,25 @@ int libretrodb_lua_to_rmsgpack_value(
break;
case LUA_TTABLE:
lua_getfield(L, value_idx, "binary");
if (!lua_isstring(L, -1)) {
if (!lua_isstring(L, -1))
{
lua_pop(L, 1);
lua_getfield(L, value_idx, "uint");
if (!lua_isnumber(L, -1)) {
if (!lua_isnumber(L, -1))
{
lua_pop(L, 1);
goto set_nil;
} else {
}
else
{
tmp_num = lua_tonumber(L, -1);
tmp_value->type = RDT_UINT;
tmp_value->val.uint_ = tmp_num;
lua_pop(L, 1);
}
} else {
}
else
{
tmp_string = lua_tolstring(L, -1, &tmp_len);
tmp_buff = malloc(tmp_len);
memcpy(tmp_buff, tmp_string, tmp_len);