Event Handling C++ ?

258 views
Skip to first unread message

AlienCoder

unread,
Jun 16, 2016, 5:19:01 AM6/16/16
to Haxe

Hello Community,

I haven't found a haxe implementation of event handling in C++ .

A haven*t found any tutorial for haxe event handling besides of flash or js targets. Are there ones?

How can I handle events in C++ ?

Kind regards
Michael

JLM

unread,
Jun 16, 2016, 6:00:19 AM6/16/16
to Haxe
Cheap event handing is just by adding a function to your class.

public var finished: Void -> Void;

then in the code

if( finished != null ) finished();

You can use bind to help with some situations.  http://haxe.org/manual/lf-function-bindings.html

once finished happens the class that created finished can check the state of the created class.  Using this approach is very light weight and fast but only really suitable for one listener. 

Alternatively if you want to go with lots of listeners approaches, which is very oop but can easily end up in event hell you might want to look at https://github.com/haxetink/tink_core#signal or some of the other features in tink.  Obviously in OpenFL/NME C++ you could use custom events with the EventDispatcher structure you may want to check out something like robotlegs port or massives stuff but often these approaches can create slower code, atleast I like the simple function approach as it's very light and fast but probably not very oop.

AlienCoder

unread,
Jun 16, 2016, 6:41:10 AM6/16/16
to Haxe

Hello JLM,

thank you for your quick reply.
This really helps me a lot.

Kind regards
Michael

AlienCoder

unread,
Jun 16, 2016, 9:57:08 AM6/16/16
to Haxe

Hello Justin,

I am sorry, to bother you with the same question.again But I was googling for examples of event handling for HAXE with .bind() for a long time. But I could not find something usefull. I only found tutorial for       haxe -> flash      or      haxe -> js

In a different post you said:

If you are not familiar with callback or bind, it is the same concept as Delegate.create in as2/as3 and explanations can easily be googled.


I am not capable to transform the following flash example to a suitable haxe analogy:


import mx.utils.Delegate;
function myClickHandler(evt)
{
        trace(evt.target);
        trace(this);
}
myBtn.addEventListener("click", Delegate.create(this,myClickHandler));


I have just finished my programming education one year ago and did not have had to deal with eventmanagement so much, yet.

So, do you have by chance a nice HAXE tutorial that can be used for C++ targets as well?

Thank you in advance.
Michael

JLM

unread,
Jun 16, 2016, 12:01:49 PM6/16/16
to Haxe
Here is one example of using bind in neko ( same as c++ haxe ). If it is something that is wired up to give an event normally you list that after the bound events in the function.
http://try-haxe.mrcdk.com/#2d12B

JLM

unread,
Jun 16, 2016, 12:05:03 PM6/16/16
to Haxe
Are you using a specific haxe toolkit like Kha, Luxe etc...  because perhaps if you provide context it would be easier to provide something less abstract.
Message has been deleted
Message has been deleted

AlienCoder

unread,
Jun 16, 2016, 1:23:30 PM6/16/16
to Haxe

Thank you for your effort.

But is this actually an event, technically seen?

I would consider a true event handling as some codesegment observing if another code segment is executed and then it gives a callback.

Something like:
The servantA tells the king if the servantB has done his work.

But your code simple is like the servantB tells the king on hisown that he has finished the work.

Or did I get something wrong?

Kind regards
Michael

PS: At the moment I do not use Kha or other frameworks. Just rudimentary haxe programming.

Philippe Elsass

unread,
Jun 16, 2016, 3:26:27 PM6/16/16
to Haxe

Yeah usually you use the observer pattern in Haxe, that is callbacks or signals, when you want to use a cross-platform approach.

Do you want to use C++ specific features like interrupts?

PS: msignal is a classic cross-target library, and it's definitely usable for C++:
https://github.com/massiveinteractive/msignal

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

AlienCoder

unread,
Jun 17, 2016, 3:27:59 AM6/17/16
to Haxe

Hello Philippe,

thank you for your answer.

I will have a look at it.

Kind regards
Michael
Reply all
Reply to author
Forward
0 new messages