rubber-generate 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +54 -0
- data/example/vte.cr +366 -0
- data/lib/rubber/codegen/enum.rb +2 -2
- data/lib/rubber/codegen/flags.rb +79 -6
- data/lib/rubber/scanner.rb +1 -1
- metadata +6 -6
- data/README.md +0 -58
data/README.textile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
h1. Rubber Generate
|
2
|
+
|
3
|
+
h2. v0.0.5
|
4
|
+
|
5
|
+
Template language for generating Ruby bindings for C libraries
|
6
|
+
by Geoff Youngs <g@intersect-uk.co.uk>
|
7
|
+
|
8
|
+
h3. Introduction
|
9
|
+
|
10
|
+
A simple ruby-style bindings generator for Ruby. It allows bindings to
|
11
|
+
be laid out in a Ruby style, documentation to be included inline and
|
12
|
+
explicit type casts within C code. It's somewhere between SWIG and pyrex.
|
13
|
+
|
14
|
+
It also allows features extconf.rb creation, including checks for headers,
|
15
|
+
pkg-config etc. The modules it creates currently depend on Ruby/GTK, but
|
16
|
+
it is planned to remove this dependency unless they genuinely require Ruby/GTK.
|
17
|
+
|
18
|
+
Other features include custom named type-maps, pre/post code inclusion within
|
19
|
+
functions and some rudimentary understanding of C code.
|
20
|
+
|
21
|
+
h3. Dependencies
|
22
|
+
|
23
|
+
* Ruby 1.8.6
|
24
|
+
|
25
|
+
h3. Example
|
26
|
+
|
27
|
+
Sample file:
|
28
|
+
|
29
|
+
* example/vte.cr
|
30
|
+
|
31
|
+
Usage:
|
32
|
+
<pre>
|
33
|
+
$ rubber-generate --generate --build vte.cr
|
34
|
+
</pre>
|
35
|
+
|
36
|
+
Which should generate
|
37
|
+
[arch]/vte.c <- Source code for extension
|
38
|
+
[arch]/vte.rd <- RD documentation from vte.cr
|
39
|
+
[arch]/extconf.rb <- Config script
|
40
|
+
[arch]/vte.o <- Object file
|
41
|
+
[arch]/vte.so <- Compiled extension
|
42
|
+
|
43
|
+
h3. Installation
|
44
|
+
|
45
|
+
<pre>
|
46
|
+
$ sudo gem install rubber-generate
|
47
|
+
</pre>
|
48
|
+
|
49
|
+
h3. Credits
|
50
|
+
|
51
|
+
Author: Geoff Youngs
|
52
|
+
|
53
|
+
Contributors:
|
54
|
+
* Vincent Isambart
|
data/example/vte.cr
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
%include vte/vte.h
|
2
|
+
|
3
|
+
%{
|
4
|
+
|
5
|
+
VALUE
|
6
|
+
long_array(long values[], int size)
|
7
|
+
{
|
8
|
+
VALUE arr;
|
9
|
+
int i;
|
10
|
+
|
11
|
+
arr = rb_ary_new();
|
12
|
+
|
13
|
+
for(i=0; i < size; i++)
|
14
|
+
rb_ary_push(arr, LONG2NUM(values[i]));
|
15
|
+
|
16
|
+
return arr;
|
17
|
+
}
|
18
|
+
char **
|
19
|
+
string_list(VALUE ary)
|
20
|
+
{
|
21
|
+
char **list = NULL;
|
22
|
+
int i;
|
23
|
+
|
24
|
+
if (NIL_P(ary))
|
25
|
+
return NULL;
|
26
|
+
|
27
|
+
list = ALLOC_N(char*, RARRAY(ary)->len + 1);
|
28
|
+
|
29
|
+
for (i = 0; i < RARRAY(ary)->len; i++)
|
30
|
+
{
|
31
|
+
list[i] = StringValuePtr(RARRAY(ary)->ptr[i]);
|
32
|
+
}
|
33
|
+
list[i] = NULL;
|
34
|
+
|
35
|
+
return list;
|
36
|
+
}
|
37
|
+
|
38
|
+
%}
|
39
|
+
|
40
|
+
|
41
|
+
%name vte
|
42
|
+
%pkg-config vte
|
43
|
+
|
44
|
+
%map VALUE > fontdescription : ((PangoFontDescription*)RVAL2BOXED((%%), PANGO_TYPE_FONT_DESCRIPTION))
|
45
|
+
%map fontdescription > VALUE : (BOXED2RVAL((void*)(%%), PANGO_TYPE_FONT_DESCRIPTION))
|
46
|
+
|
47
|
+
%map VALUE > GdkColor* : ((GdkColor*)RVAL2BOXED((%%), GDK_TYPE_COLOR))
|
48
|
+
%map GdkColor* > VALUE : (BOXED2RVAL((void*)(%%), GDK_TYPE_COLOR))
|
49
|
+
|
50
|
+
%map long* > VALUE : long_array(%%, (sizeof(%%) / sizeof(%%[0])))
|
51
|
+
%map VALUE > char** : string_list(%%)
|
52
|
+
|
53
|
+
%map GdkPixbuf* > VALUE : GOBJ2RVAL(%%)
|
54
|
+
%map VALUE > GdkPixbuf* : GDK_PIXBUF(RVAL2GOBJ(%%))
|
55
|
+
|
56
|
+
|
57
|
+
=begin
|
58
|
+
= VTE Terminal Widget
|
59
|
+
|
60
|
+
The VTE widget is a new terminal widget meant to replace zvt. It is used by gnome-terminal as of GNOME 2.2.x
|
61
|
+
|
62
|
+
== Features
|
63
|
+
=== Unicode support
|
64
|
+
Recently added support for UTF-8 display, select and paste. Currently supports fixed-width, iso10646-encoded and wide fonts.
|
65
|
+
|
66
|
+
=== Background pixmaps
|
67
|
+
A very fast implementation of background pixmaps and pseudo-transparency means all users can have beautiful desktops without heavily impacting their work.
|
68
|
+
|
69
|
+
=== Secure and portable
|
70
|
+
Only a small external program is required to interact directly with the operating system and pseudo tty interface. This is easily ported to different Unix systems and auditable for security.
|
71
|
+
|
72
|
+
=== Easy to use and feature rich
|
73
|
+
Through a simple api adding a complete terminal execution environment to any application (including secure tty setup and utmp/wtmp logging) is next to trivial (3-4 function calls). It can also be used as a direct text display engine with colour/attributes and cursor addressible display without the need for a separate sub-process.
|
74
|
+
|
75
|
+
Features include configurable colours, pixmaps/transparency, beeps, blinking cursor, selecting by word characters, and more. Plus all the usual stuff like selection/pasting, and scrollback buffer.
|
76
|
+
|
77
|
+
=== xterm compatible
|
78
|
+
It aims towards being a terminal-compatible dropin for the xterm program. This is to aid interoperability with foreign systems. The rarely used Tektronix graphics terminal component has been dropped however.
|
79
|
+
|
80
|
+
=== Dingus Click
|
81
|
+
Allows auto highlighting of a set of text matching a regular expression. Used by the gnome-terminal to launch a web-browser when the user shift-clicks on a URL.
|
82
|
+
|
83
|
+
=== Actively developed
|
84
|
+
Steadily improving feature set and stability.
|
85
|
+
|
86
|
+
=end
|
87
|
+
module VTE
|
88
|
+
gobject Terminal < VTE_TYPE_TERMINAL : Gtk::Widget
|
89
|
+
def initialize()
|
90
|
+
=begin
|
91
|
+
Create a new terminal widget
|
92
|
+
|
93
|
+
* Returns: new instance of VTE::Terminal
|
94
|
+
=end
|
95
|
+
RBGTK_INITIALIZE(self, vte_terminal_new());
|
96
|
+
end
|
97
|
+
|
98
|
+
def uint:fork_command(char *command, char ** argv, char ** envv, char *dir, bool lastlog = FALSE, bool utmp = FALSE, bool wtmp = FALSE)
|
99
|
+
=begin
|
100
|
+
Fork the child process for the terminal, e.g. terminal.fork_command("/bin/sh", nil, nil, ENV['HOME'])
|
101
|
+
|
102
|
+
* Returns: pid of child process
|
103
|
+
=end
|
104
|
+
pid_t pid = 0;
|
105
|
+
|
106
|
+
pid = vte_terminal_fork_command(VTE_TERMINAL(_self), command, argv, envv, dir,
|
107
|
+
lastlog, utmp, wtmp);
|
108
|
+
|
109
|
+
if (argv)
|
110
|
+
free(argv);
|
111
|
+
if (envv)
|
112
|
+
free(envv);
|
113
|
+
|
114
|
+
return pid;
|
115
|
+
end
|
116
|
+
|
117
|
+
def feed(T_STRING str)
|
118
|
+
=begin
|
119
|
+
Send data to the terminal
|
120
|
+
=end
|
121
|
+
vte_terminal_feed(VTE_TERMINAL(_self), RSTRING(str)->ptr, RSTRING(str)->len);
|
122
|
+
end
|
123
|
+
|
124
|
+
def feed_child(T_STRING str)
|
125
|
+
=begin
|
126
|
+
Send data to the child process
|
127
|
+
=end
|
128
|
+
vte_terminal_feed_child(VTE_TERMINAL(_self), RSTRING(str)->ptr, RSTRING(str)->len);
|
129
|
+
end
|
130
|
+
|
131
|
+
def cursor_position()
|
132
|
+
=begin
|
133
|
+
Get the current cursor position
|
134
|
+
=end
|
135
|
+
long arr[2];
|
136
|
+
vte_terminal_get_cursor_position(VTE_TERMINAL(_self), &arr[0], &arr[1]);
|
137
|
+
return <arr:ruby>;
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_padding()
|
141
|
+
=begin
|
142
|
+
Get the padding the widget is using.
|
143
|
+
=end
|
144
|
+
long arr[2];
|
145
|
+
vte_terminal_get_padding(VTE_TERMINAL(_self), (int*)&arr[0], (int*)&arr[1]);
|
146
|
+
return <arr:ruby>;
|
147
|
+
end
|
148
|
+
|
149
|
+
#################### Misc settings
|
150
|
+
def scrollback_lines=(long lines)
|
151
|
+
=begin
|
152
|
+
Set the number of scrollback lines, above or at an internal minimum.
|
153
|
+
=end
|
154
|
+
vte_terminal_set_scrollback_lines(VTE_TERMINAL(_self), lines);
|
155
|
+
end
|
156
|
+
|
157
|
+
def set_size(long x, long y)
|
158
|
+
=begin
|
159
|
+
Set the terminal size.
|
160
|
+
=end
|
161
|
+
vte_terminal_set_size(VTE_TERMINAL(_self), x, y);
|
162
|
+
end
|
163
|
+
|
164
|
+
def cursor_blinks=(bool blink)
|
165
|
+
=begin
|
166
|
+
Set whether or not the cursor blinks.
|
167
|
+
=end
|
168
|
+
vte_terminal_set_cursor_blinks(VTE_TERMINAL(_self), blink);
|
169
|
+
end
|
170
|
+
|
171
|
+
def reset(bool full=TRUE, bool clear_history=TRUE)
|
172
|
+
=begin
|
173
|
+
Reset the terminal, optionally clearing the tab stops and line history.
|
174
|
+
=end
|
175
|
+
vte_terminal_reset(VTE_TERMINAL(_self), full, clear_history);
|
176
|
+
end
|
177
|
+
|
178
|
+
#################### Fonts
|
179
|
+
def bool:using_xft?()
|
180
|
+
=begin
|
181
|
+
Is the terminal using Xft to render text?
|
182
|
+
|
183
|
+
* Returns: Boolean
|
184
|
+
=end
|
185
|
+
return vte_terminal_get_using_xft(VTE_TERMINAL(_self));
|
186
|
+
end
|
187
|
+
|
188
|
+
def font=(VALUE font)
|
189
|
+
=begin
|
190
|
+
Set the terminal font.
|
191
|
+
((|font|)) is either a String or Pango::FontDescription
|
192
|
+
=end
|
193
|
+
if (TYPE(font) == T_DATA)
|
194
|
+
vte_terminal_set_font(VTE_TERMINAL(_self), <font:fontdescription>);
|
195
|
+
else
|
196
|
+
vte_terminal_set_font_from_string(VTE_TERMINAL(_self), <font:string>);
|
197
|
+
end
|
198
|
+
|
199
|
+
def fontdescription:font()
|
200
|
+
=begin
|
201
|
+
Get the terminal's current font description.
|
202
|
+
|
203
|
+
* Returns: Pango::FontDescription
|
204
|
+
=end
|
205
|
+
return vte_terminal_get_font(VTE_TERMINAL(_self));
|
206
|
+
end
|
207
|
+
|
208
|
+
def bool:allow_bold?()
|
209
|
+
=begin
|
210
|
+
Check whether the terminal allows bold text?
|
211
|
+
|
212
|
+
* Returns: Boolean
|
213
|
+
=end
|
214
|
+
return vte_terminal_get_allow_bold(VTE_TERMINAL(_self));
|
215
|
+
end
|
216
|
+
|
217
|
+
def allow_bold=(bool allow)
|
218
|
+
=begin
|
219
|
+
Set whether the terminal allows bold text
|
220
|
+
=end
|
221
|
+
vte_terminal_set_allow_bold(VTE_TERMINAL(_self), allow);
|
222
|
+
end
|
223
|
+
|
224
|
+
#################### Clipboard
|
225
|
+
def copy()
|
226
|
+
=begin
|
227
|
+
Copy the current selection to the clipboard
|
228
|
+
=end
|
229
|
+
vte_terminal_copy_clipboard(VTE_TERMINAL(_self));
|
230
|
+
end
|
231
|
+
def paste()
|
232
|
+
=begin
|
233
|
+
Paste the current clipboard contents into the terminal
|
234
|
+
=end
|
235
|
+
vte_terminal_paste_clipboard(VTE_TERMINAL(_self));
|
236
|
+
end
|
237
|
+
def copy_primary()
|
238
|
+
=begin
|
239
|
+
Copy the current selection as the primary selection
|
240
|
+
=end
|
241
|
+
vte_terminal_copy_primary(VTE_TERMINAL(_self));
|
242
|
+
end
|
243
|
+
def paste_primary()
|
244
|
+
=begin
|
245
|
+
Paste the current primary selection into the terminal
|
246
|
+
=end
|
247
|
+
vte_terminal_paste_primary(VTE_TERMINAL(_self));
|
248
|
+
end
|
249
|
+
def bool:has_selection?()
|
250
|
+
=begin
|
251
|
+
Paste the current primary selection into the terminal
|
252
|
+
=end
|
253
|
+
return vte_terminal_get_has_selection(VTE_TERMINAL(_self));
|
254
|
+
end
|
255
|
+
|
256
|
+
#################### Mouse
|
257
|
+
def mouse_autohide=(bool hide)
|
258
|
+
=begin
|
259
|
+
Paste the current primary selection into the terminal
|
260
|
+
=end
|
261
|
+
vte_terminal_set_mouse_autohide(VTE_TERMINAL(_self), hide);
|
262
|
+
end
|
263
|
+
|
264
|
+
def bool:mouse_autohide?()
|
265
|
+
=begin
|
266
|
+
Paste the current primary selection into the terminal
|
267
|
+
=end
|
268
|
+
return vte_terminal_get_mouse_autohide(VTE_TERMINAL(_self));
|
269
|
+
end
|
270
|
+
|
271
|
+
#################### Matched text
|
272
|
+
def int:match_add(T_REGEXP text)
|
273
|
+
=begin
|
274
|
+
Add a matching expression, returning the tag the widget assigns to that expression
|
275
|
+
=end
|
276
|
+
return vte_terminal_match_add(VTE_TERMINAL(_self), RREGEXP(text)->str);
|
277
|
+
end
|
278
|
+
|
279
|
+
def match_remove(int tag)
|
280
|
+
=begin
|
281
|
+
Remove a matching expression by tag
|
282
|
+
=end
|
283
|
+
vte_terminal_match_remove(VTE_TERMINAL(_self), tag);
|
284
|
+
end
|
285
|
+
def match_check(long column, long row)
|
286
|
+
=begin
|
287
|
+
Check for a matched tag at a given position
|
288
|
+
=end
|
289
|
+
char *text;
|
290
|
+
int tag;
|
291
|
+
|
292
|
+
text = vte_terminal_match_check(VTE_TERMINAL(_self),
|
293
|
+
column, row,
|
294
|
+
&tag);
|
295
|
+
if (text)
|
296
|
+
return rb_ary_new3(2, <text:ruby>, <tag:ruby>);
|
297
|
+
else
|
298
|
+
return Qnil;
|
299
|
+
end
|
300
|
+
|
301
|
+
#################### Properities
|
302
|
+
def gobject:adjustment()
|
303
|
+
=begin
|
304
|
+
* Returns: the Gtk::Adjustment for the widget
|
305
|
+
=end
|
306
|
+
return vte_terminal_get_adjustment(VTE_TERMINAL(_self));
|
307
|
+
end
|
308
|
+
def string:title()
|
309
|
+
=begin
|
310
|
+
* Returns: the terminal's title
|
311
|
+
=end
|
312
|
+
return vte_terminal_get_window_title(VTE_TERMINAL(_self));
|
313
|
+
end
|
314
|
+
def string:icon_title()
|
315
|
+
=begin
|
316
|
+
* Returns: the terminal's icon title
|
317
|
+
=end
|
318
|
+
return vte_terminal_get_icon_title(VTE_TERMINAL(_self));
|
319
|
+
end
|
320
|
+
def long:char_width()
|
321
|
+
return vte_terminal_get_char_width(VTE_TERMINAL(_self));
|
322
|
+
end
|
323
|
+
def long:char_height()
|
324
|
+
return vte_terminal_get_char_height(VTE_TERMINAL(_self));
|
325
|
+
end
|
326
|
+
def long:char_ascent()
|
327
|
+
return vte_terminal_get_char_ascent(VTE_TERMINAL(_self));
|
328
|
+
end
|
329
|
+
def long:char_descent()
|
330
|
+
return vte_terminal_get_char_descent(VTE_TERMINAL(_self));
|
331
|
+
end
|
332
|
+
def long:row_count()
|
333
|
+
return vte_terminal_get_row_count(VTE_TERMINAL(_self));
|
334
|
+
end
|
335
|
+
def long:column_count()
|
336
|
+
return vte_terminal_get_column_count(VTE_TERMINAL(_self));
|
337
|
+
end
|
338
|
+
|
339
|
+
################### Fancy backgrounds
|
340
|
+
def background_image=(T_DATA|T_STRING image)
|
341
|
+
if (TYPE(image)==T_STRING)
|
342
|
+
vte_terminal_set_background_image_file(VTE_TERMINAL(_self),
|
343
|
+
StringValuePtr(image));
|
344
|
+
else
|
345
|
+
vte_terminal_set_background_image(VTE_TERMINAL(_self), <{VALUE>GdkPixbuf*:image}>);
|
346
|
+
end
|
347
|
+
alias :set_background_image :background_image=
|
348
|
+
|
349
|
+
def set_color_background(GdkColor *color)
|
350
|
+
vte_terminal_set_color_background(VTE_TERMINAL(_self),
|
351
|
+
color);
|
352
|
+
end
|
353
|
+
alias :background_color= :set_color_background
|
354
|
+
|
355
|
+
def set_color_foreground(GdkColor *color)
|
356
|
+
vte_terminal_set_color_foreground(VTE_TERMINAL(_self),
|
357
|
+
color);
|
358
|
+
end
|
359
|
+
alias :foreground_color= :set_color_foreground
|
360
|
+
|
361
|
+
def set_background_saturation(double saturation)
|
362
|
+
vte_terminal_set_background_saturation(VTE_TERMINAL(_self), saturation);
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
end
|
data/lib/rubber/codegen/enum.rb
CHANGED
@@ -39,7 +39,7 @@ static VALUE make_enum_value(VALUE klass, int value, char *name, char *fullname)
|
|
39
39
|
|
40
40
|
return Data_Wrap_Struct(klass, NULL, free, data);
|
41
41
|
}
|
42
|
-
static int
|
42
|
+
static int enum_value_to_int(VALUE value, VALUE klass)
|
43
43
|
{
|
44
44
|
switch (TYPE(value))
|
45
45
|
{
|
@@ -160,7 +160,7 @@ __attribute__ ((unused))
|
|
160
160
|
io.puts " case #{arg}: return #{default_cname}_#{arg};"
|
161
161
|
end
|
162
162
|
io.puts "}; return Qnil; }"
|
163
|
-
io.puts "static int enum_ruby_to_#{name}(VALUE val) { return
|
163
|
+
io.puts "static int enum_ruby_to_#{name}(VALUE val) { return enum_value_to_int(val, #{cname}); }"
|
164
164
|
end
|
165
165
|
include RegisterChildren
|
166
166
|
def default_cname
|
data/lib/rubber/codegen/flags.rb
CHANGED
@@ -17,7 +17,7 @@ class C_Flags
|
|
17
17
|
io.puts "static VALUE #{cname};"
|
18
18
|
unless @@declared_base
|
19
19
|
@@declared_base = true
|
20
|
-
io.puts
|
20
|
+
io.puts <<-EOHEADER
|
21
21
|
|
22
22
|
static VALUE flagsBaseClass;
|
23
23
|
|
@@ -38,7 +38,7 @@ static VALUE make_flags_value(VALUE klass, int value, char *name, char *fullname
|
|
38
38
|
|
39
39
|
return Data_Wrap_Struct(klass, NULL, free, data);
|
40
40
|
}
|
41
|
-
static int
|
41
|
+
static int flags_value_to_int(VALUE value, VALUE klass)
|
42
42
|
{
|
43
43
|
switch (TYPE(value))
|
44
44
|
{
|
@@ -136,11 +136,78 @@ static VALUE rubber_flags_coerce(VALUE value, VALUE other)
|
|
136
136
|
}
|
137
137
|
}
|
138
138
|
|
139
|
-
|
139
|
+
static VALUE rubber_flags_and(VALUE value, VALUE other)
|
140
|
+
{
|
141
|
+
FlagsData *data = NULL;
|
142
|
+
int original = 0;
|
143
|
+
int other_num = 0;
|
144
|
+
|
145
|
+
Data_Get_Struct(value, FlagsData, data);
|
146
|
+
|
147
|
+
original = data->value;
|
148
|
+
|
149
|
+
other_num = flags_value_to_int(value, CLASS_OF(value));
|
150
|
+
|
151
|
+
// return INT2NUM(original & other_num);
|
152
|
+
return make_flags_value(CLASS_OF(value), original & other_num, "", "");
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE rubber_flags_or(VALUE value, VALUE other)
|
156
|
+
{
|
157
|
+
FlagsData *data = NULL;
|
158
|
+
int original = 0;
|
159
|
+
int other_num = 0;
|
160
|
+
|
161
|
+
Data_Get_Struct(value, FlagsData, data);
|
162
|
+
|
163
|
+
original = data->value;
|
164
|
+
|
165
|
+
other_num = flags_value_to_int(value, CLASS_OF(value));
|
166
|
+
|
167
|
+
return make_flags_value(CLASS_OF(value), original | other_num, "", "");
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
EOHEADER
|
140
173
|
end
|
141
174
|
args.each do |arg|
|
142
175
|
io.puts "static VALUE #{default_cname}_#{arg} = Qnil;"
|
143
|
-
end
|
176
|
+
end
|
177
|
+
io.puts <<-EO_INSPECT
|
178
|
+
static VALUE rubber_#{default_cname}_flags_inspect(VALUE value)
|
179
|
+
{
|
180
|
+
FlagsData *data = NULL;
|
181
|
+
volatile VALUE str = rb_str_new(\"#<\", 2);
|
182
|
+
char number[16] = "";
|
183
|
+
int c=0;
|
184
|
+
|
185
|
+
Data_Get_Struct(value, FlagsData, data);
|
186
|
+
|
187
|
+
rb_str_cat2(str, rb_obj_classname(value));
|
188
|
+
rb_str_cat2(str, " - ");
|
189
|
+
EO_INSPECT
|
190
|
+
args.each do |arg|
|
191
|
+
uniq = arg[@strip..-1]
|
192
|
+
io.puts <<-EOARG
|
193
|
+
if ((data->value & #{arg})==#{arg}) {
|
194
|
+
if (c>0)
|
195
|
+
rb_str_cat2(str, ", ");
|
196
|
+
rb_str_cat2(str, #{uniq.downcase.gsub(/_/,'-').inspect});
|
197
|
+
c ++;
|
198
|
+
}
|
199
|
+
EOARG
|
200
|
+
end
|
201
|
+
io.puts <<-EO_INSPECT
|
202
|
+
rb_str_cat2(str, " (");
|
203
|
+
sprintf(number, "%i", data->value);
|
204
|
+
rb_str_cat2(str, number);
|
205
|
+
rb_str_cat2(str, ")>");
|
206
|
+
|
207
|
+
return str;
|
208
|
+
}
|
209
|
+
EO_INSPECT
|
210
|
+
|
144
211
|
io.puts "typedef int #{name};
|
145
212
|
#ifdef __GNUC__
|
146
213
|
// No point in declaring these unless we're using GCC
|
@@ -158,8 +225,10 @@ __attribute__ ((unused))
|
|
158
225
|
args.each do |arg|
|
159
226
|
io.puts " case #{arg}: return #{default_cname}_#{arg};"
|
160
227
|
end
|
161
|
-
io.puts
|
162
|
-
|
228
|
+
io.puts <<-EOB
|
229
|
+
}; return make_flags_value(#{cname}, value, "various", "Various"); }
|
230
|
+
static int flags_ruby_to_#{name}(VALUE val) { return flags_value_to_int(val, #{cname}); }
|
231
|
+
EOB
|
163
232
|
end
|
164
233
|
include RegisterChildren
|
165
234
|
def default_cname
|
@@ -209,6 +278,8 @@ __attribute__ ((unused))
|
|
209
278
|
io.puts ' rb_define_method(flagsBaseClass, "fullname", rubber_flags_to_s, 0);'
|
210
279
|
io.puts ' rb_define_method(flagsBaseClass, "name", rubber_flags_name, 0);'
|
211
280
|
io.puts ' rb_define_method(flagsBaseClass, "<=>", rubber_flags_cmp, 0);'
|
281
|
+
io.puts ' rb_define_method(flagsBaseClass, "&", rubber_flags_and, 1);'
|
282
|
+
io.puts ' rb_define_method(flagsBaseClass, "|", rubber_flags_or, 1);'
|
212
283
|
io.puts ' '
|
213
284
|
end
|
214
285
|
if parent
|
@@ -216,6 +287,8 @@ __attribute__ ((unused))
|
|
216
287
|
else
|
217
288
|
io.puts " #{cname} = rb_define_class(#{name.inspect}, flagsBaseClass);"
|
218
289
|
end
|
290
|
+
io.puts ' rb_define_method('+cname+', "inspect", rubber_'+default_cname+'_flags_inspect, 0);'
|
291
|
+
|
219
292
|
|
220
293
|
args.each do |arg|
|
221
294
|
uniq = arg[@strip..-1]
|
data/lib/rubber/scanner.rb
CHANGED
@@ -234,7 +234,7 @@ def _scan(fp)
|
|
234
234
|
puts "GCPool #{name}"
|
235
235
|
stack.first.classes.push(C_GCRefPool.new(name))
|
236
236
|
|
237
|
-
elsif state.in_func == false and @str.skip(/(enum)(?= )/x) # C Enum as module wrapper
|
237
|
+
elsif state.in_func == false and @str.skip(/(enum|flags)(?= )/x) # C Enum as module wrapper
|
238
238
|
what = @str[1]
|
239
239
|
@str.skip(/\s+/)
|
240
240
|
name = @str.scan(/[A-Z][a-z_0-9A-Z]*/)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Geoff Youngs
|
@@ -25,7 +25,7 @@ executables:
|
|
25
25
|
extensions: []
|
26
26
|
|
27
27
|
extra_rdoc_files:
|
28
|
-
- README.
|
28
|
+
- README.textile
|
29
29
|
files:
|
30
30
|
- bin/rubber-generate
|
31
31
|
- lib/rubber/autord.rb
|
@@ -50,7 +50,7 @@ files:
|
|
50
50
|
- lib/rubber/scanner.rb
|
51
51
|
- lib/rubber/struct.rb
|
52
52
|
- lib/rubber/types.rb
|
53
|
-
- README.
|
53
|
+
- README.textile
|
54
54
|
has_rdoc: true
|
55
55
|
homepage: http://github.com/geoffyoungs/rubber-generate
|
56
56
|
licenses: []
|
@@ -81,5 +81,5 @@ rubygems_version: 1.3.6
|
|
81
81
|
signing_key:
|
82
82
|
specification_version: 3
|
83
83
|
summary: Template language for generating Ruby bindings for C libraries
|
84
|
-
test_files:
|
85
|
-
|
84
|
+
test_files:
|
85
|
+
- example/vte.cr
|
data/README.md
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
Rubber C Binder v0.0.5
|
2
|
-
Template language for generating Ruby bindings for C libraries
|
3
|
-
by Geoff Youngs <g@intersect-uk.co.uk>
|
4
|
-
|
5
|
-
Introduction
|
6
|
-
~~~~~~~~~~~~
|
7
|
-
A simple ruby-style bindings generator for Ruby. It allows bindings to
|
8
|
-
be laid out in a Ruby style, documentation to be included inline and
|
9
|
-
explicit type casts within C code. It's somewhere between SWIG and pyrex.
|
10
|
-
|
11
|
-
It also allows features extconf.rb creation, including checks for headers,
|
12
|
-
pkg-config etc. The modules it creates currently depend on Ruby/GTK, but
|
13
|
-
it is planned to remove this dependency unless they genuinely require Ruby/GTK.
|
14
|
-
|
15
|
-
Other features include custom named type-maps, pre/post code inclusion within
|
16
|
-
functions and some rudimentary understanding of C code.
|
17
|
-
|
18
|
-
|
19
|
-
Dependencies
|
20
|
-
~~~~~~~~~~~~
|
21
|
-
Ruby 1.8
|
22
|
-
Doesn't require any modules which aren't in the Ruby 1.8.0 distribution.
|
23
|
-
Ruby 1.6
|
24
|
-
Has not been tested. Requires at least the StringScanner (C version) and
|
25
|
-
StringIO modules. (See raa.ruby-lang.org for 'strscan' and 'stringio')
|
26
|
-
|
27
|
-
|
28
|
-
Example
|
29
|
-
~~~~~~~
|
30
|
-
Sample file:
|
31
|
-
vte/vte.cr
|
32
|
-
|
33
|
-
Usage:
|
34
|
-
$ ruby rubber.rb vte.cr
|
35
|
-
|
36
|
-
Which should generate
|
37
|
-
vte.c <- Source code for extension
|
38
|
-
vte.rd <- RD documentation from vte.cr
|
39
|
-
extconf.rb <- Config script
|
40
|
-
|
41
|
-
Running extconf.rb should then allow installation of the extension as normal.
|
42
|
-
|
43
|
-
|
44
|
-
Installation
|
45
|
-
~~~~~~~~~~~~
|
46
|
-
There is currently no installation. Rubber will automatically look for it's
|
47
|
-
libraries in the normal path or in the directory where the 'real' rubber script
|
48
|
-
resides. (So the rubber.rb can be symlinked from where you unpacked it to
|
49
|
-
a directory in your path).
|
50
|
-
|
51
|
-
When rubber matures then it will come with a proper install.rb setup.
|
52
|
-
|
53
|
-
|
54
|
-
Credits
|
55
|
-
~~~~~~~
|
56
|
-
Rubber was created by Geoff Youngs
|
57
|
-
|
58
|
-
Contributors: Vincent Isambart
|