-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrudl.h
114 lines (88 loc) · 3.18 KB
/
rudl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* RUDL - a C library wrapping SDL for use in Ruby. Copyright (C) 2001 Danny van Bruggen */
#ifndef _RUDL_H
#define _RUDL_H
//
#define RUDLVERSION_MAJOR 0
#define RUDLVERSION_MINOR 7
#define RUDLVERSION_PATCH 1
//
#include "ruby.h"
#include "rubyio.h"
#include <SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
// Define a boolean type
#define bool int
#define false (0)
#define true (1)
// Definitions of several error catching macro's.
// DEBUG_I and DEBUG_S print an integer or string to stdout, but only in a debug build.
// ASSERT and VERIFY raise an exception when their argument is false,
// but ASSERTs only happen in a debug build.
// RUDL_* raise our own error message,
// SDL_* raise the current SDL error message.
#ifdef DEBUG_RUDL
#define DEBUG_I(____i) {char koe[500];sprintf(koe, "puts '(%i)'", ____i); rb_eval_string(koe);}
#define DEBUG_S(____s) {char koe[500];sprintf(koe, "puts '(%s)'", ____s); rb_eval_string(koe);}
#define RUDL_ASSERT(____x, ____msg) {if(!(____x)){SDL_RAISE_S(____msg);}}
#define RUDL_VERIFY(____x, ____msg) {if(!(____x)){SDL_RAISE_S(____msg);}}
#define SDL_ASSERT(____x) {if(!(____x)){SDL_RAISE;}}
#define SDL_VERIFY(____x) {if(!(____x)){SDL_RAISE;}}
#else
#define DEBUG_I(____i) {}
#define DEBUG_S(____s) {}
#define RUDL_ASSERT(____x, ____msg) {}
#define RUDL_VERIFY(____x, ____msg) {if(!(____x)){SDL_RAISE_S(____msg);}}
#define SDL_ASSERT(____x) {}
#define SDL_VERIFY(____x) {if(!(____x)){SDL_RAISE;}}
#endif
// Throws a Ruby exception
#define SDL_RAISE {rb_raise(classSDLError, SDL_GetError());}
#define SDL_RAISE_S(____s) {rb_raise(classSDLError, ____s);}
#ifdef WIN32
#define DECKLSPECKL __declspec(dllexport)
#else
#define DECKLSPECKL
#endif
#ifdef __cplusplus
#define VALUEFUNC(f) ((VALUE (*)(void))f)
#define VOIDFUNC(f) ((void (*)(...))f)
#else
#define VALUEFUNC(f) (f)
#define VOIDFUNC(f) (f)
#endif
extern Uint32 PARAMETER2FLAGS(VALUE flagsArg);
extern void initSDL();
extern VALUE moduleRUDL;
extern VALUE classSDLError;
extern VALUE moduleConstant;
extern VALUE classPit;
extern VALUE id_new;
extern VALUE id_clone;
extern VALUE rb_range_first(VALUE obj); // Why no predefined range-access functions?
extern VALUE rb_range_last(VALUE obj);
#define NUM2BOOL(____b) ((____b)==Qtrue? true:false)
#define INT2BOOL(____b) ((____b) ? Qtrue : Qfalse)
#define DBL2NUM(x) rb_float_new(x)
#define FLT2NUM(x) rb_float_new(x)
#define CSTR2STR(x) rb_str_new2(x)
#define NUM2Sint32(x) ((Sint32)NUM2INT(x))
#define NUM2Uint32(x) ((Uint32)NUM2UINT(x))
#define NUM2Sint16(x) ((Sint16)NUM2INT(x))
#define NUM2Uint16(x) ((Uint16)NUM2UINT(x))
#define NUM2Sint8(x) ((Sint8)NUM2INT(x))
#define NUM2Uint8(x) ((Uint8)NUM2UINT(x))
#define NUM2FLT(x) ((float)NUM2DBL(x))
#define RUDL_MIN(a, b) ((a)<(b)?(a):(b))
#define RUDL_MAX(a, b) ((a)>(b)?(a):(b))
#define DEC_CONST(x) rb_define_const(moduleConstant, #x, UINT2NUM(SDL_##x));
#define DEC_CONSTK(x) rb_define_const(moduleConstant, #x, UINT2NUM(SDL##x));
#define DEC_CONSTN(x) rb_define_const(moduleConstant, #x, UINT2NUM(x));
#define rb_define_singleton_and_instance_method(clas, name, func, args) \
rb_define_method(clas, name, func, args);\
rb_define_singleton_method(clas, name, func, args);
#ifdef __cplusplus
}
#endif
#endif