static SV * list_item_to_sv ( hexchat_list *list, const char *const *fields ) { HV *hash = newHV(); SV *field_value; const char *field; int field_index = 0; const char *field_name; int name_len; while (fields[field_index] != NULL) { field_name = fields[field_index] + 1; name_len = strlen (field_name); switch (fields[field_index][0]) { case 's': field = hexchat_list_str (ph, list, field_name); if (field != NULL) { field_value = newSVpvn (field, strlen (field)); } else { field_value = &PL_sv_undef; } break; case 'p': field_value = newSViv (PTR2IV (hexchat_list_str (ph, list, field_name))); break; case 'i': field_value = newSVuv (hexchat_list_int (ph, list, field_name)); break; case 't': field_value = newSVnv (hexchat_list_time (ph, list, field_name)); break; default: field_value = &PL_sv_undef; } (void)hv_store (hash, field_name, name_len, field_value, 0); field_index++; } return sv_2mortal (newRV_noinc ((SV *) hash)); }
static inline int list_marshal(lua_State *L, const char *key, hexchat_list *list) { char const *str = hexchat_list_str(ph, list, key); int number; if(str) { if(!strcmp(key, "context")) { hexchat_context **u = lua_newuserdata(L, sizeof(hexchat_context *)); *u = (hexchat_context *)str; luaL_newmetatable(L, "context"); lua_setmetatable(L, -2); return 1; } lua_pushstring(L, str); return 1; } number = hexchat_list_int(ph, list, key); if(number != -1) { lua_pushinteger(L, number); return 1; } if (list != NULL) { time_t tm = hexchat_list_time(ph, list, key); if(tm != -1) { lua_pushinteger(L, tm); return 1; } } lua_pushnil(L); return 1; }