Exemple #1
0
// caller must be in the main thread
VALUE CRScriptCore::eval_string(char* p, int cb)
{
	VALUE module = Qnil;
	CRubyWrapper::GetCWrapper()->GetCurrentEngine()->GetModule(reinterpret_cast<PUINT_PTR>(&module));
        VALUE args[] = { rb_str_new(p, cb), rb_str_new("ActiveScriptRuby", 16), INT2NUM(1) };
        return rb_obj_instance_eval(3, args, module);
}
Exemple #2
0
// invoked in the main thread
void CRScriptCore::DefineGlobalProperties(LPCSTR pObjName)
{
	static char merge[] = "begin\r\n"
		                     "%c%s.ole_put_methods.map{|x| x.name} | %c%s.ole_get_methods.map{|x| x.name}\r\n"
					      "rescue RuntimeError\r\n"
						     "[]\r\n"
						  "end\r\n";
	size_t alloclen = sizeof(merge) + strlen(pObjName) * 2 + 16;
	char* p = reinterpret_cast<LPSTR>(alloca(alloclen + 1));
	int cb = sprintf(p, merge, prefix, pObjName, prefix, pObjName);
#if defined(__IRubyEngine_INTERFACE_DEFINED__)
        VALUE args[] = { rb_str_new(p, cb), rb_str_new("ActiveScriptRuby", 16), INT2NUM(1) };
        VALUE a = rb_obj_instance_eval(3, args, GetModuleValue());
#else
	VALUE a = rb_eval_string(p);
#endif
	for (int i = 0; i < RARRAY_LEN(a); i++)
	{
		VALUE name = rb_ary_entry(a, i);
		char* prop = StringValueCStr(name);
		if (strlen(prop) > alloclen)
		{
			continue;	// too long name
		}
		sprintf(p, "$%s", prop);
		rb_define_virtual_variable(p, (VALUE(*)(ANYARGS))GlobalGetter, (void(*)(ANYARGS))GlobalSetter);
	}
}
Exemple #3
0
static VALUE
control_block_initialize(int argc, VALUE *argv, VALUE cb)
{
    VALUE file, mode;
    VALUE args[2];
    rb_scan_args(argc, argv, "02", &file, &mode);
    if (RTEST(file)){ 
      args[0] = file;
      args[1] = mode;
      control_block_open(1, (VALUE *)args, cb);
    }
    if (rb_block_given_p()) rb_obj_instance_eval( 0, 0, cb );
    return cb;
}
Exemple #4
0
/**
 * Call MontageImages.
 *
 * Ruby usage:
 *   - @verbatim ImageList#montage <{parm block}> @endverbatim
 *
 * Notes:
 *   - Creates Montage object, yields to block if present in Montage object's
 *     scope.
 *
 * @param self this object
 * @return a new image list
 */
VALUE
ImageList_montage(VALUE self)
{
    VALUE montage_obj;
    Montage *montage;
    Image *new_images, *images;
    ExceptionInfo *exception;

    // Create a new instance of the Magick::Montage class
    montage_obj = rm_montage_new();
    if (rb_block_given_p())
    {
        // Run the block in the instance's context, allowing the app to modify the
        // object's attributes.
        (void) rb_obj_instance_eval(0, NULL, montage_obj);
    }

    Data_Get_Struct(montage_obj, Montage, montage);

    images = images_from_imagelist(self);

    // If app specified a non-default composition operator, use it for all images.
    if (montage->compose != UndefinedCompositeOp)
    {
        Image *i;
        for (i = images; i; i = GetNextImageInList(i))
        {
            i->compose = montage->compose;
        }
    }

    exception = AcquireExceptionInfo();

    // MontageImage can return more than one image.
    new_images = MontageImages(images, montage->info, exception);
    rm_split(images);
    rm_check_exception(exception, new_images, DestroyOnError);
    (void) DestroyExceptionInfo(exception);

    rm_ensure_result(new_images);

    RB_GC_GUARD(montage_obj);

    return rm_imagelist_from_images(new_images);
}
Exemple #5
0
// invoked in the main thread
void CRScriptCore::DefineGlobalMethods(LPCSTR pObjName)
{
	static char methoddef[] = "def %s(*a)\r\n"
		                      "  %c%s.%s(*a)\r\n"
						 	  "end\r\n";
	static const int MAX_PROPNAME = 64;
	char* p = reinterpret_cast<LPSTR>(alloca(sizeof(methoddef) + strlen(pObjName) + MAX_PROPNAME * 2 + 8));
	int state;
    VALUE param[] = {
		GetOleObject(s_valueWin32OleEx, m_strGlobalObjectName.c_str()), 
	    rb_intern("ole_func_methods"), 
		0,
	};
    VALUE a = rb_protect((VALUE(*)(VALUE))funcall, (VALUE)param, &state);
	if (state)
	{	// maybe no typelib
		return;
	}
	ID name = rb_intern("name");
	for (int i = 0; i < RARRAY_LEN(a); i++)
	{
		VALUE o = rb_ary_entry(a, i);
		VALUE propname = rb_funcall(o, name, 0);
		char* prop = StringValueCStr(propname);
		if (strlen(prop) > MAX_PROPNAME) 
		{
			continue; // skip, the name is too long
		}
#define LOWER_PROP_NAME
#ifdef LOWER_PROP_NAME
		char method[65];
		strcpy(method, prop);
		method[0] = tolower(method[0]);
		int cb = sprintf(p, methoddef, method, prefix, pObjName, prop);
#else
		int cb = sprintf(p, methoddef, prop, prefix, pObjName, prop);
#endif
#if defined(__IRubyEngine_INTERFACE_DEFINED__)
                VALUE args[] = { rb_str_new(p, cb), rb_str_new("ActiveScriptRuby", 16), INT2NUM(1) };
                rb_obj_instance_eval(3, args, GetModuleValue());
#else
		rb_eval_string(p);
#endif
	}
}
Exemple #6
0
/*
    Function:   rm_get_optional_arguments
    Purpose:    Collect optional method arguments via Magick::OptionalMethodArguments
    Notes:      Creates an instance of Magick::OptionalMethodArguments, then yields
                to a block in the context of the instance.
*/
void
rm_get_optional_arguments(VALUE img)
{
  volatile VALUE OptionalMethodArguments;
  volatile VALUE opt_args;
  VALUE argv[1];

  // opt_args = Magick::OptionalMethodArguments.new(img)
  // opt_args.instance_eval { block }
  if (rb_block_given_p())
  {
      OptionalMethodArguments = rb_const_get_from(Module_Magick, rb_intern("OptionalMethodArguments"));
      argv[0] = img;
      opt_args = rb_class_new_instance(1, argv, OptionalMethodArguments);
      (void) rb_obj_instance_eval(0, NULL, opt_args);
  }

  return;
}
Exemple #7
0
bool RubyApp::OnInit()
{
	wxApp::OnInit();

#ifdef __WXMAC__
     ProcessSerialNumber psn;
 
     GetCurrentProcess( &psn );
     CPSEnableForegroundOperation( &psn );
     SetFrontProcess( &psn );
#endif

	RubyWX::Color::define_const();
	RubyWX::Font::define_const();
	RubyWX::Brush::define_const();
	RubyWX::Pen::define_const();

#if wxUSE_INTL
	wxLocale::CreateLanguagesDB();
	mLocale = new wxLocale(wxLANGUAGE_DEFAULT);
	mLocale->AddCatalog("wxstd");
#ifdef __LINUX__
	mLocale->AddCatalog("fileutils");
#endif
#endif
#if wxUSE_PROPGRID
	wxPropertyGrid::RegisterAdditionalEditors();
#endif

	this->Bind(wxEVT_ASYNC_METHOD_CALL,AppAfter());

	ruby_app_inited = true;

	bool result = RTEST(rb_funcall(mRuby, rb_intern("on_init"), 0));
	if(rb_block_given_p())
		rb_obj_instance_eval(0, 0, mRuby);
	return result;
}
Exemple #8
0
/*
    Method:     Draw#annotate(img, w, h, x, y, text) <{optional parms}>
    Purpose:    annotates an image with text
    Returns:    self
    Notes:      Additional Draw attribute methods may be called in the
                optional block, which is executed in the context of an
                Draw object.
*/
VALUE Draw_annotate(
                   VALUE self,
                   VALUE image_arg,
                   VALUE width_arg,
                   VALUE height_arg,
                   VALUE x_arg,
                   VALUE y_arg,
                   VALUE text)
{
    Draw *draw;
    Image *image;
    unsigned long width, height;
    long x, y;
    AffineMatrix keep;
    char geometry_str[50];

    // Save the affine matrix in case it is modified by
    // Draw#rotation=
    Data_Get_Struct(self, Draw, draw);
    keep = draw->info->affine;

    image_arg = rm_cur_image(image_arg);
    image = rm_check_frozen(image_arg);

    // If we have an optional parm block, run it in self's context,
    // allowing the app a chance to modify the object's attributes
    if (rb_block_given_p())
    {
        (void)rb_obj_instance_eval(0, NULL, self);
    }

    // Translate & store in Draw structure
#if defined(HAVE_INTERPRETIMAGEPROPERTIES)
    draw->info->text = InterpretImageProperties(NULL, image, StringValuePtr(text));
#else
    draw->info->text = InterpretImageAttributes(NULL, image, StringValuePtr(text));
#endif
    if (!draw->info->text)
    {
        rb_raise(rb_eArgError, "no text");
    }

    // Create geometry string, copy to Draw structure, overriding
    // any previously existing value.
    width  = NUM2ULONG(width_arg);
    height = NUM2ULONG(height_arg);
    x      = NUM2LONG(x_arg);
    y      = NUM2LONG(y_arg);

    if (width == 0 && height == 0)
    {
        sprintf(geometry_str, "%+ld%+ld", x, y);
    }

    // WxH is non-zero
    else
    {
        sprintf(geometry_str, "%lux%lu%+ld%+ld", width, height, x, y);
    }

    magick_clone_string(&draw->info->geometry, geometry_str);

    (void) AnnotateImage(image, draw->info);

    magick_free(draw->info->text);
    draw->info->text = NULL;
    draw->info->affine = keep;

    rm_check_image_exception(image, RetainOnError);

    return self;
}
Exemple #9
0
static VALUE object_spec_rb_obj_instance_eval(VALUE self, VALUE obj) {
  return rb_obj_instance_eval(0, NULL, obj);
}