Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 66 lines (58 sloc) 1.317 kb
9c1d230 committing experimental branch content
Laurent Sansonetti authored
1 /* -*-c-*- */
2 /*
3 * from eval.c
4 */
5
6 /* exit */
7
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a lib...
Laurent Sansonetti authored
8 // TODO: move & lock me into RoxorCore
9 static VALUE at_exit_procs = Qnil;
9c1d230 committing experimental branch content
Laurent Sansonetti authored
10
11 /*
12 * call-seq:
13 * at_exit { block } -> proc
14 *
15 * Converts _block_ to a +Proc+ object (and therefore
16 * binds it at the point of call) and registers it for execution when
17 * the program exits. If multiple handlers are registered, they are
18 * executed in reverse order of registration.
19 *
20 * def do_at_exit(str1)
21 * at_exit { print str1 }
22 * end
23 * at_exit { puts "cruel world" }
24 * do_at_exit("goodbye ")
25 * exit
26 *
27 * <em>produces:</em>
28 *
29 * goodbye cruel world
30 */
31
32 static VALUE
33 rb_f_at_exit(VALUE self, SEL sel)
34 {
35 if (!rb_block_given_p()) {
36 rb_raise(rb_eArgError, "called without a block");
37 }
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a lib...
Laurent Sansonetti authored
38 VALUE proc = rb_block_proc();
39 rb_ary_push(at_exit_procs, proc);
9c1d230 committing experimental branch content
Laurent Sansonetti authored
40 return proc;
41 }
42
43 void
44 rb_exec_end_proc(void)
45 {
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a lib...
Laurent Sansonetti authored
46 while (true) {
47 const int count = RARRAY_LEN(at_exit_procs);
48 if (count > 0) {
49 VALUE proc = RARRAY_AT(at_exit_procs, count - 1);
50 rb_ary_delete_at(at_exit_procs, count - 1);
51 rb_proc_call2(proc, 0, NULL);
52 continue;
9c1d230 committing experimental branch content
Laurent Sansonetti authored
53 }
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a lib...
Laurent Sansonetti authored
54 break;
9c1d230 committing experimental branch content
Laurent Sansonetti authored
55 }
56 }
57
58 void
59 Init_jump(void)
60 {
cbe906e introduce rb_objc_define_module_function() which mimics the ruby spec
Laurent Sansonetti authored
61 rb_objc_define_module_function(rb_mKernel, "at_exit", rb_f_at_exit, 0);
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a lib...
Laurent Sansonetti authored
62
63 at_exit_procs = rb_ary_new();
64 GC_RETAIN(at_exit_procs);
9c1d230 committing experimental branch content
Laurent Sansonetti authored
65 }
Something went wrong with that request. Please try again.