static XS (XS_Xchat_context_info) { const char *const *fields; dXSARGS; if (items > 0 ) { xchat_print (ph, "Usage: Xchat::Internal::context_info()"); } fields = xchat_list_fields (ph, "channels" ); XPUSHs (list_item_to_sv (NULL, fields)); XSRETURN (1); }
/* * lua: xchat.list_fields(name) * desc: returns the possible keys for name as table * ret: table ;-> * args: * * name (string): name of the wanted list ("channels", "dcc", * "ignore", "notify", "users") */ static int lxc_list_fields(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *const *fields = xchat_list_fields(ph, name); int i; lua_newtable(L); i = 0; while (fields[i] != NULL) { lua_pushnumber(L, i); /* first char is the type ... */ lua_pushstring(L, fields[i]+1); lua_settable(L, -3); } return 1; }
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; }