2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "rubyutils.h"
15 Point
value2point(VALUE p
) {
19 int x
= NUM2INT(rb_funcall(p
, rb_intern("x"), 0));
20 int y
= NUM2INT(rb_funcall(p
, rb_intern("y"), 0));
25 VALUE
point2value(const Point
& p
) {
27 return rb_funcall(rb_eval_string("Point"), rb_intern("new"), 2, INT2FIX(p
.x
), INT2FIX(p
.y
));
32 static VALUE
wrapped_call(VALUE
* args
) {
35 int argc
= NUM2INT((VALUE
)args
[2]);
36 VALUE
* fun_args
= args
+ 3;
38 return rb_funcall2(rcpt
, id
, argc
, fun_args
);
42 VALUE
pcall(int* res
, VALUE rcpt
, ID id
) {
47 return rb_protect((VALUE(*)(VALUE
))wrapped_call
, (VALUE
)args
, res
);
50 VALUE
pcall(int* res
, VALUE rcpt
, ID id
, VALUE arg1
) {
56 return rb_protect((VALUE(*)(...))wrapped_call
, (VALUE
)args
, res
);
59 VALUE
pcall(int* res
, VALUE rcpt
, ID id
, VALUE arg1
, VALUE arg2
) {
66 return rb_protect((VALUE(*)(...))wrapped_call
, (VALUE
)args
, res
);
70 VALUE
pcall(int* res
, VALUE rcpt
, ID id
, VALUE arg1
, VALUE arg2
, VALUE arg3
) {
78 return rb_protect((VALUE(*)(...))wrapped_call
, (VALUE
)args
, res
);