static int num_open_dccs (void) { xchat_list *list; int num = 0; list = xchat_list_get (ph, "dcc"); if (!list) return 0; while (xchat_list_next (ph, list)) { /* check only ACTIVE dccs */ if (xchat_list_int (ph, list, "status") == 1) { /* check only SEND dccs */ if (xchat_list_int (ph, list, "type") == 0) num++; } } xchat_list_free (ph, list); return num; }
static XS (XS_Xchat_get_list) { SV *name; xchat_list *list; const char *const *fields; int count = 0; /* return value for scalar context */ dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::get_list(name)"); } else { SP -= items; /*remove the argument list from the stack */ name = ST (0); list = xchat_list_get (ph, SvPV_nolen (name)); if (list == NULL) { XSRETURN_EMPTY; } if (GIMME_V == G_SCALAR) { while (xchat_list_next (ph, list)) { count++; } xchat_list_free (ph, list); XSRETURN_IV ((IV) count); } fields = xchat_list_fields (ph, SvPV_nolen (name)); while (xchat_list_next (ph, list)) { XPUSHs (list_item_to_sv (list, fields)); } xchat_list_free (ph, list); PUTBACK; return; } }
/* * lua: xchat.list_get(name) * desc: http://xchat.org/docs/plugin20.html#lists :) * time_t values are stored as number => e.g. * os.date("%Y-%m-%d, %H:%M:%S", time_t_value) * pointers (channel -> context) as number... untested if this works * ret: table with tables with all keys=Name, value=(Type)... or nil on error * args: * * name (string): the wanted list */ static int lxc_list_get(lua_State *L) { const char *name = luaL_checkstring(L, 1); int i; /* item index */ int l; /* list index */ const char *str; double num; time_t date; long ptr; const char *const *fields = xchat_list_fields(ph, name); xchat_list *list = xchat_list_get(ph, name); if (!list) { lua_pushnil(L); return 1; } lua_newtable(L); /* this is like the perl plugin does it ;-) */ l = 1; while (xchat_list_next(ph, list)) { i = 0; lua_pushnumber(L, l); lua_newtable(L); while (fields[i] != NULL) { switch (fields[i][0]) { case 's': str = xchat_list_str(ph, list, fields [i] + 1); lua_pushstring(L, fields[i]+1); if (str != NULL) lua_pushstring(L, str); else lua_pushnil(L); lua_settable(L, -3); break; case 'p': ptr = (long)xchat_list_str(ph, list, fields [i] + 1); num = (double)ptr; lua_pushstring(L, fields[i]+1); lua_pushnumber(L, num); lua_settable(L, -3); break; case 'i': num = (double)xchat_list_int(ph, list, fields[i] + 1); lua_pushstring(L, fields[i]+1); lua_pushnumber(L, num); lua_settable(L, -3); break; case 't': date = xchat_list_time(ph, list, fields[i] + 1); lua_pushstring(L, fields[i]+1); lua_pushnumber(L, (double)date); lua_settable(L, -3); break; } i++; } lua_settable(L, -3); l++; } xchat_list_free(ph, list); return 1; }
static void static_free_xchat_list( xchat_list *list ) { xchat_list_free( static_plugin_handle, list ); }