Finished chess animator.
[tagua/yd.git] / src / rubyutils.cpp
blobf3c73893f39ba4b39f9616a1ee9f097f68938bb7
1 /*
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.
9 */
11 #include "rubyutils.h"
13 namespace Ruby {
15 Point value2point(VALUE p) {
16 if (NIL_P(p))
17 return Point();
18 else {
19 int x = NUM2INT(rb_funcall(p, rb_intern("x"), 0));
20 int y = NUM2INT(rb_funcall(p, rb_intern("y"), 0));
21 return Point(x, y);
25 VALUE point2value(const Point& p) {
26 if (p.valid())
27 return rb_funcall(rb_eval_string("Point"), rb_intern("new"), 2, INT2FIX(p.x), INT2FIX(p.y));
28 else
29 return Qnil;
32 static VALUE wrapped_call(VALUE* args) {
33 VALUE rcpt = args[0];
34 ID id = (ID)args[1];
35 int argc = NUM2INT((VALUE)args[2]);
36 VALUE* fun_args = args + 3;
38 return rb_funcall2(rcpt, id, argc, fun_args);
41 #if 0
42 VALUE pcall(int* res, VALUE rcpt, ID id) {
43 VALUE args[3];
44 args[0] = rcpt;
45 args[1] = (VALUE)id;
46 args[2] = 0;
47 return rb_protect((VALUE(*)(VALUE))wrapped_call, (VALUE)args, res);
50 VALUE pcall(int* res, VALUE rcpt, ID id, VALUE arg1) {
51 VALUE args[4];
52 args[0] = rcpt;
53 args[1] = (VALUE)id;
54 args[2] = 1;
55 args[3] = arg1;
56 return rb_protect((VALUE(*)(...))wrapped_call, (VALUE)args, res);
59 VALUE pcall(int* res, VALUE rcpt, ID id, VALUE arg1, VALUE arg2) {
60 VALUE args[5];
61 args[0] = rcpt;
62 args[1] = (VALUE)id;
63 args[2] = 2;
64 args[3] = arg1;
65 args[4] = 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) {
71 VALUE args[6];
72 args[0] = rcpt;
73 args[1] = (VALUE)id;
74 args[2] = 2;
75 args[3] = arg1;
76 args[4] = arg2;
77 args[5] = arg3;
78 return rb_protect((VALUE(*)(...))wrapped_call, (VALUE)args, res);
80 #endif