Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Callbacks in Ruby?

For general discussion related FlowStone

Callbacks in Ruby?

Postby Exo » Tue Jan 27, 2015 11:04 pm

I would like to implement a callback system in Ruby.

Here is a simple example of what I mean...
Callback.fsm
(1.15 KiB) Downloaded 940 times


This doesn't work because the output method is not recognized within the class.

The benefits of this should be obvious we could send data from anywhere in the schematic to anywhere else, like sending data from low down in the hierarchy back to the top (which is what I intend to do)

So is there a way to get this to work?
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Exo
 
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK

Re: Callbacks in Ruby?

Postby KG_is_back » Wed Jan 28, 2015 12:22 am

I believe the problem is, that "output" is a function of RubyEdit class. And the Callback class you've created doesn't inherit from RubyEdit, which means "output" is not declared for it.

In order for it to work, you have to send it the module it resides in when initialized... look at this fix:

Code: Select all

class Callback
def initialize(mod)
@module=mod
end


def doSomething()
    @module.output "go" , nil
end

end

@call = Callback.new(self)
output "callback", @call



KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Callbacks in Ruby?

Postby RJHollins » Wed Jan 28, 2015 5:57 am

alright .... you Guys are amazing :shock: 8-)

Even if I don't understand the how or why ... it's still is fascinating to try and follow new techniques.

Thanks !!
8-)
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Callbacks in Ruby?

Postby Exo » Wed Jan 28, 2015 7:45 am

Ah yes thanks KG. I had a brain freeze, should have realised output was part of RubyEdit.

Thanks.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Exo
 
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK

Re: Callbacks in Ruby?

Postby Tronic » Wed Jan 28, 2015 12:19 pm

why not just use the #send __send__ methods?
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Postby Exo » Wed Jan 28, 2015 12:32 pm

I wasn't aware of these methods. Can you give an example?

I'm not well versed in Ruby so I tend to default to doing things the 'Java' way.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Exo
 
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK

Re: Callbacks in Ruby?

Postby Tronic » Wed Jan 28, 2015 3:54 pm

This is an example of __send__ method
I used the $intern_this gloabal variable to get the local instance of RubyEdit Class
to inherit it's intenal declared methods.

Callback_(Tronic).fsm
(1.16 KiB) Downloaded 920 times
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Postby MyCo » Wed Jan 28, 2015 5:01 pm

Tronic wrote:I used the $intern_this gloabal variable to get the local instance of RubyEdit Class
to inherit it's intenal declared methods.


This doesn't work, because $intern_this seems to point to the last edited Ruby-Edit, not to the class that contains the code.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Callbacks in Ruby?

Postby Tronic » Wed Jan 28, 2015 5:22 pm

yes you're right, but I think it's a problem of FS, for as the module is initialized,
but if you retrig the class it works correctly.
the $intern_this, it seems to me, point to the current RubyEdit module.

Edit: work only for the last call of Callback class, so Myco you you're right.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Postby Tronic » Wed Jan 28, 2015 6:49 pm

However my example of callback with the method __send__ works well,
the only problem is if you want to inherit the methods of class RubyEdit.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 61 guests