From: Stephen Kellett Date: 2004-11-30T05:32:48+09:00 Subject: How to implement set_trace_func callback in C/C++? Hello everybody, I'm trying to implement the callback for set_trace_func in C++. Think of it as C if thats any easier. Shown at the bottom of this posting is my sample application which runs the standard "Hello World" ruby program. My callback function "my_trace_function" gets called. Problem is I don't know how to access the event, file, line, id, binding and classname parameters passed to the function which I'd have access to if coding in Ruby. Can anyone tell me how to get the parameters passed to the callback function? Have I got the function prototype correct? Etc. I've shown it as 3 VALUEs as that is what I think it is. Is it really implemented as varargs or something else? Hoping you can help. (Yes, I really do need the callback implemented in C or C++, which is why I'm using C/C++ for the callback and not Ruby for the callback). I've done a Google on this subject and not found anyone else doing this. Stephen #include "ruby.h" VALUE my_trace_function(VALUE count, VALUE args, VALUE other) { // is args an array? If so how to access properly // I keep getting errors if I treat args as an array. return 0; } int main(int argc, char* argv[]) { NtInitialize(&argc, &argv); ruby_init(); ruby_script("embedded"); VALUE module; module = rb_define_module("TRACEMODULE"); rb_define_module_function(module, "my_trace_func", (unsigned long (__cdecl *)(...))my_trace_function, -1); rb_eval_string( "set_trace_func proc {|*data| TRACEMODULE.my_trace_func(*data)}"); rb_load_file("e:\\ruby\\samples\\hello.rb"); ruby_run(); return 0; } -- Stephen Kellett Object Media Limited http://www.objmedia.demon.co.uk RSI Information: http://www.objmedia.demon.co.uk/rsi.html