[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    [ruby-talk:00151] Re: Win32 callback into Ruby code?
From:       matz () netlab ! co ! jp (Yukihiro Matsumoto)
Date:       1998-12-27 15:35:05
[Download RAW message or body]

Hi.

In message "[ruby-talk:00145] Win32 callback into Ruby code?"
    on 98/12/25, "Bryce" <crowdog@siscom.net> writes:

|I have not seen this anywhere for Ruby but I was
|wondering if anyone knows of a way of using a Ruby
|function as a "callback" in a Win32 environment?
|
|Example:
|    myRubyfunction ()
|        print "a"
|    end
|
|    win32.somefunction (  &myRubyFunction )
|
|    # now, somefunction will callback to myRubyFunction

Well, Ruby can objectify blocks and methods, but you can't get C
function pointer out of them.  (It maybe possible if Ruby has a full
compiler.)  It's not Ruby's fault, but just C can't have closures in
portable way.  But most of the case, callbacks receive the client
data, so you can pass Ruby procedure object as client data, and invoke
it in the callback function, to emulate closures.

                                                matz.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic