4 $:.unshift File.dirname(__FILE__)
8 def mkfunc(rettype, fnum, argc)
9 args = (0..(argc-1)).collect{|i| "long arg#{i}"}.join(", ")
11 subst_code = (0..(argc-1)).collect{|i|
12 " buff[#{i.to_s}] = arg#{i.to_s};"
16 if( DLTYPE[rettype][:c2rb] )
17 " return #{DLTYPE[rettype][:rb2c]['retval']};"
19 " /* no return value */"
23 "static #{DLTYPE[rettype][:ctype]}",
24 "rb_dl_callback_func_#{rettype.to_s}_#{fnum.to_s}(#{args})",
26 " VALUE retval, proto, proc, obj;",
27 " VALUE argv[#{argc.to_s}];",
29 " long buff[#{argc.to_s}];",
33 " obj = rb_hash_aref(DLFuncTable, rb_assoc_new(INT2NUM(#{rettype.to_s}),INT2NUM(#{fnum.to_s})));",
35 " rb_raise(rb_eDLError, \"callback function does not exist in DL::FuncTable\");",
36 " Check_Type(obj, T_ARRAY);",
37 " proto = rb_ary_entry(obj, 0);",
38 " proc = rb_ary_entry(obj, 1);",
39 " Check_Type(proto, T_STRING);",
40 " if( RSTRING(proto)->len >= #{argc.to_s} )",
41 " rb_raise(rb_eArgError, \"too many arguments\");",
42 " rb_dl_scan_callback_args(buff, RSTRING(proto)->ptr, &argc, argv);",
43 " retval = rb_funcall2(proc, id_call, argc, argv);",
52 DLTYPE.keys.sort.each{|t|
53 for n in 0..(MAX_CALLBACK - 1)
54 print(mkfunc(t, n, 15), "\n\n")