static XS (XS_Xchat_emit_print) { char *event_name; int RETVAL; int count; dXSARGS; if (items < 1) { xchat_print (ph, "Usage: Xchat::emit_print(event_name, ...)"); } else { event_name = (char *) SvPV_nolen (ST (0)); RETVAL = 0; /* we need to figure out the number of defined values passed in */ for (count = 0; count < items; count++) { if (!SvOK (ST (count))) { break; } } switch (count) { case 1: RETVAL = xchat_emit_print (ph, event_name, NULL); break; case 2: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), NULL); break; case 3: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), SvPV_nolen (ST (2)), NULL); break; case 4: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), SvPV_nolen (ST (2)), SvPV_nolen (ST (3)), NULL); break; case 5: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), SvPV_nolen (ST (2)), SvPV_nolen (ST (3)), SvPV_nolen (ST (4)), NULL); break; } XSRETURN_IV (RETVAL); } }
static VALUE static_ruby_xchat_emit_print( int argc, VALUE *argv, VALUE klass ) { char *event; char *parms[16]; int i; printf( "[argc: %d]\n", argc ); if( argc < 1 ) return Qfalse; event = StringValueCStr( argv[0] ); for( i = 1; i < 16; i++ ) { if( i >= argc ) parms[i-1] = NULL; else parms[i-1] = StringValueCStr( argv[i] ); } i = xchat_emit_print( static_plugin_handle, event, parms[ 0], parms[ 1], parms[ 2], parms[ 3], parms[ 4], parms[ 5], parms[ 6], parms[ 7], parms[ 8], parms[ 9], parms[10], parms[11], parms[12], parms[13], parms[14], parms[15], NULL ); return ( i ? Qtrue : Qfalse ); }
/* * lua: xchat.emit_print(event, text, [text2, ...]) * desc: Generates a print event. This can be any event found in the * Preferences > Advanced > Text Events window. The vararg parameter * list MUST be no longer than four (4) parameters. * Special care should be taken when calling this function inside a * print callback (from xchat.hook_print()), as not to cause endless * recursion. * ret: true on success, false on error * args: * * event (string): the event name from the references > Advanced > * Text Events window * * text (string) * text2 (string) * ... (string(s)): * parameters for the given event */ static int lxc_emit_print(lua_State *L) { int n = lua_gettop(L); const char *text[5]; const char *event; int i = 2; if (n > 6) luaL_error(L, "too many arguments to xchat.emit_print()"); event = luaL_checkstring(L, 1); while (i <= n) { text[i-2] = luaL_checkstring(L, i); i++; } switch (n-1) { case 0: i = xchat_emit_print(ph, event, NULL); break; case 1: i = xchat_emit_print(ph, event, text[0], NULL); break; case 2: i = xchat_emit_print(ph, event, text[0], text[1], NULL); break; case 3: i = xchat_emit_print(ph, event, text[0], text[1], text[2], NULL); break; case 4: i = xchat_emit_print(ph, event, text[0], text[1], text[2], text[3], NULL); break; } lua_pushboolean(L, (i == 0) ? 0 : 1); return 1; }