/* * call-seq: * marshal_load(array) -> nil * * Provides marshalling support for use by the Marshal library. * * */ DLL_LOCAL VALUE _marshal_load(VALUE self, VALUE data) { data = rb_Array(data); _setWidth(self, RARRAY_AREF(data,0)); _setHeight(self, RARRAY_AREF(data,1)); return Qnil; }
static VALUE range_last(VALUE range, SEL sel, int argc, VALUE *argv) { if (argc == 0) { return RANGE_END(range); } return rary_last(rb_Array(range), 0, argc, argv); }
static VALUE range_last(int argc, VALUE *argv, VALUE range) { VALUE rb_ary_last(int, VALUE *, VALUE); if (argc == 0) return RANGE_END(range); return rb_ary_last(argc, argv, rb_Array(range)); }
DLL_LOCAL VALUE _setCustomColors(VALUE self,VALUE val) { rb_check_frozen(self); VALUE dp = rb_Array(val); wxColourData &data = _self->GetColourData(); for(std::size_t i = 0; i < wxColourData::NUM_CUSTOM && i < (std::size_t)RARRAY_LEN(dp); ++i) data.SetCustomColour(i,unwrap<wxColor>(RARRAY_AREF(dp,i))); return val; }
/* * call-seq: * io.winsize = [rows, columns] * * Tries to set console size. The effect depends on the platform and * the running environment. * * You must require 'io/console' to use this method. */ static VALUE console_set_winsize(VALUE io, VALUE size) { rb_io_t *fptr; rb_console_size_t ws; #if defined _WIN32 HANDLE wh; int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; const VALUE *sz; int fd; GetOpenFile(io, fptr); size = rb_Array(size); rb_check_arity(RARRAY_LENINT(size), 2, 4); sz = RARRAY_CONST_PTR(size); row = sz[0], col = sz[1], xpixel = sz[2], ypixel = sz[3]; fd = GetWriteFD(fptr); #if defined TIOCSWINSZ ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); SET(xpixel); SET(ypixel); #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 wh = (HANDLE)rb_w32_get_osfhandle(fd); #define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); #undef SET if (!NIL_P(xpixel)) (void)NUM2UINT(xpixel); if (!NIL_P(ypixel)) (void)NUM2UINT(ypixel); if (!GetConsoleScreenBufferInfo(wh, &ws)) { rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) { rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) { rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); } #endif return io; }
std::vector<std::string> unwrap< std::vector<std::string> >(const VALUE &val ) { std::vector<std::string> vec; VALUE temp(rb_Array(val)); std::size_t count = RARRAY_LEN(temp); for(std::size_t i = 0; i != count; ++i) { vec.push_back(unwrap<std::string>(RARRAY_AREF(temp,i))); } return vec; }
/* * call-seq: * io.winsize = [rows, columns] * * Tries to set console size. The effect depends on the platform and * the running environment. * * You must require 'io/console' to use this method. */ static VALUE console_set_winsize(VALUE io, VALUE size) { rb_io_t *fptr; rb_console_size_t ws; #if defined _WIN32 HANDLE wh; int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; #if defined TIOCSWINSZ int fd; #endif GetOpenFile(io, fptr); size = rb_Array(size); rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22", &row, &col, &xpixel, &ypixel); #if defined TIOCSWINSZ fd = GetWriteFD(fptr); ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); SET(xpixel); SET(ypixel); #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr)); newrow = (SHORT)NUM2UINT(row); newcol = (SHORT)NUM2UINT(col); if (!getwinsize(GetReadFD(fptr), &ws)) { rb_sys_fail("GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { if (!(SetConsoleScreenBufferSize(wh, ws.dwSize) || SET_LAST_ERROR)) { rb_sys_fail("SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; if (!(SetConsoleWindowInfo(wh, FALSE, &ws.srWindow) || SET_LAST_ERROR)) { rb_sys_fail("SetConsoleWindowInfo"); } #endif return io; }
static void prepare_writev(struct wrv_args *a, VALUE io, VALUE ary) { a->io = io; a->fd = my_fileno(io); a->something_written = 0; if (TYPE(ary) == T_ARRAY) /* rb_ary_subseq will not copy array unless it modified */ a->buf = MY_ARY_SUBSEQ(ary, 0, RARRAY_LEN(ary)); else a->buf = rb_Array(ary); a->vec_buf = rb_str_new(0, 0); a->vec = NULL; }
/* call-seq: * stylesheet.apply(document, {params}) -> XML::Document * * Apply this stylesheet transformation to the provided document. * This method may be invoked multiple times. * * Params: * * document - An instance of an XML::Document * * params - An optional hash table that specifies the values for xsl:param values embedded in the stylesheet. * * Example: * * stylesheet_doc = XML::Document.file('stylesheet_file') * stylesheet = XSLT::Stylesheet.new(stylesheet_doc) * * xml_doc = XML::Document.file('xml_file') * result = stylesheet.apply(xml_doc) * result = stylesheet.apply(xml_doc, {:foo => 'bar'}) */ static VALUE ruby_xslt_stylesheet_apply(int argc, VALUE *argv, VALUE self) { xmlDocPtr xdoc; xsltStylesheetPtr xstylesheet; xmlDocPtr result; VALUE document; VALUE params; int i; char** pParams; if (argc > 2 || argc < 1) rb_raise(rb_eArgError, "wrong number of arguments (need 1 or 2)"); document = argv[0]; if (!rb_obj_is_kind_of(document, cXMLDocument)) rb_raise(rb_eTypeError, "Must pass in an XML::Document instance."); /* Make sure params is a flat array */ params = (argc == 2 ? argv[1]: Qnil); params = rb_Array(params); rb_funcall(params, rb_intern("flatten!"), 0); pParams = ruby_xslt_coerce_params(params); Data_Get_Struct(document, xmlDoc, xdoc); Data_Get_Struct(self, xsltStylesheet, xstylesheet); result = xsltApplyStylesheet(xstylesheet, xdoc, (const char**)pParams); if (!result) rb_raise(eXSLTError, "Transformation failed"); /* Free allocated array of *chars. Note we don't have to free the last array item since its set to NULL. */ for (i=0; i<RARRAY_LEN(params); i++) { ruby_xfree(pParams[i]); } ruby_xfree(pParams); return rxml_document_wrap(result); }
/* * call-seq: * marshal_load(array) -> self * * Provides marshalling support for use by the Marshal library. * * */ DLL_LOCAL VALUE _marshal_load(VALUE self,VALUE data) { data = rb_Array(data); VALUE tmp = RARRAY_AREF(data,3); unsigned char* alpha = NULL; if(!NIL_P(tmp)) alpha = (unsigned char*)StringValuePtr(tmp); VALUE val = RARRAY_AREF(data,2); _self->Create( RB_NUM2UINT(RARRAY_AREF(data,0)),RB_NUM2UINT(RARRAY_AREF(data,1)), (unsigned char*)StringValuePtr(val),alpha); _setMask(self,RARRAY_AREF(data,4)); #if wxUSE_PALETTE _setPalette(self,RARRAY_AREF(data,5)); #endif return self; }
/* * call-seq: * marshal_load(array) -> nil * * Provides marshalling support for use by the Marshal library. * * */ DLL_LOCAL VALUE _marshal_load(VALUE self,VALUE data) { data = rb_Array(data); _self->Create( RB_NUM2INT(RARRAY_AREF(data,0)), unwrapenum<wxFontFamily>(RARRAY_AREF(data,1)), unwrapenum<wxFontStyle>(RARRAY_AREF(data,2)), unwrapenum<wxFontWeight>(RARRAY_AREF(data,3)), RTEST(RARRAY_AREF(data,4)), unwrap<wxString>(RARRAY_AREF(data,6)), #ifdef HAVE_RUBY_ENCODING_H unwrapenum<wxFontEncoding>(RARRAY_AREF(data,7)) #else wxFONTENCODING_DEFAULT #endif ); _setStrikethrough(self,RARRAY_AREF(data,5)); return self; }
static VALUE array_spec_rb_Array(VALUE self, VALUE object) { return rb_Array(object); }