/* * call-seq: * conn.getline( async = nil) -> str * conn.getline( async = nil) { ... } -> str * * Reads a line from the backend server after a +COPY+ command. * Returns +nil+ for EOF. * * If async is +true+ and no data is available then the block will be called * and its value will be returned. * * Call this method inside a block passed to +copy_stdout+. See * there for an example. */ VALUE pgconn_getline( int argc, VALUE *argv, VALUE self) { struct pgconn_data *c; VALUE as; int async; char *b; int r; async = rb_scan_args( argc, argv, "01", &as) > 0 && !NIL_P( as) ? 1 : 0; Data_Get_Struct( self, struct pgconn_data, c); r = PQgetCopyData( c->conn, &b, async); if (r > 0) { VALUE ret; ret = pgconn_mkstringn( c, b, r); PQfreemem( b); rb_lastline_set( ret); return ret; } else if (r == 0) return rb_yield( Qnil); else { /* PQgetResult() will be called in the ensure block. */ } return Qnil; }
void ex_rubydo(exarg_T *eap) { int state; linenr_T i; if (ensure_ruby_initialized()) { if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) return; for (i = eap->line1; i <= eap->line2; i++) { VALUE line; line = vim_str2rb_enc_str((char *)ml_get(i)); rb_lastline_set(line); eval_enc_string_protect((char *) eap->arg, &state); if (state) { error_print(state); break; } line = rb_lastline_get(); if (!NIL_P(line)) { if (TYPE(line) != T_STRING) { EMSG(_("E265: $_ must be an instance of String")); return; } ml_replace(i, (char_u *) StringValuePtr(line), 1); changed(); #ifdef SYNTAX_HL syn_changed(i); /* recompute syntax hl. for this line */ #endif } } check_cursor(); update_curbuf(NOT_VALID); } }
static VALUE global_spec_rb_lastline_set(VALUE self, VALUE line) { rb_lastline_set(line); return Qnil; }