#include "rb_Global.h" // Internals from ruby that aren't included in the ruby lib #include "RubySourceSupport.h" #include "eval_intern.h" /*********** * Global * ***********/ void Init_senderGlobal() { rb_define_global_function( "__sender__", rb_RPRuby_Sender___sender__, 0 ); rb_define_global_function( "__caller__", rb_RPRuby_Sender___caller__, 0 ); } /*************************************************************************************************************************************************************** **************************************************************************************************************************************************************** Ruby Global Methods **************************************************************************************************************************************************************** ***************************************************************************************************************************************************************/ /*************** * __sender__ * ***************/ /* * call-seq: * __sender__ -> object * * Return object sending message to receiver. */ VALUE rb_RPRuby_Sender___sender__() { // get the frame prior to current frame rb_control_frame_t* c_sending_frame = RPRuby_internal_framePriorTo( NULL ); // make sure the current frame wasn't the first frame or return nil if ( c_sending_frame == NULL ) { return Qnil; } // assuming we have a previous frame, return its rb_self (our current receiver's sender) return c_sending_frame->self; } /*************** * __caller__ * ***************/ /* * call-seq: * __caller__ -> object * * Return method sending message to receiver. */ VALUE rb_RPRuby_Sender___caller__() { // get the frame prior to current frame rb_control_frame_t* c_sending_frame = RPRuby_internal_framePriorTo( NULL ); // make sure the current frame wasn't the first frame or return nil if ( c_sending_frame == NULL ) { return Qnil; } return ID2SYM( frame_func_id( c_sending_frame ) ); }