Best strategy class on multi target

182 views
Skip to first unread message

Tim M

unread,
Apr 13, 2017, 11:29:03 PM4/13/17
to Haxe
When building a class on different targets what have you found to be the best strategy?

For example, if I need a generic Socket.hx class, how do you keep yourself organized when targeting -swf -hl etc? So far we're using conditional compile (#if #else) on the target instance declaration, but I was thinking we could use a internal implementation with inlines:

#if flash
import flash.SocketImpl
#else if hl
import hl.SocketImpl
#end

class Socket {
var socket:SockImpl;
}



Thoughts?

Franco Ponticelli

unread,
Apr 14, 2017, 12:12:03 AM4/14/17
to Haxe
My preference is for old style interfaces.
--
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.

Tim M

unread,
Apr 14, 2017, 3:13:50 PM4/14/17
to Haxe
Thanks for the reply Franco,

Can you elaborate on the specifics? Are you conditional compiling each include? A gist would be nice.

Philippe Elsass

unread,
Apr 14, 2017, 4:09:54 PM4/14/17
to Haxe
We often use typedef declarations and import them like classes:

// video/PlayerVideo.hx
package video;
#if flash
typedef PlayerVideo = video.flash.PlayerVideoImpl;
#else
typedef PlayerVideo = video.js.PlayerVideoImpl;
#end 

Nicolas Cannasse

unread,
Apr 15, 2017, 4:07:51 AM4/15/17
to haxe...@googlegroups.com
In Haxe 3.4 you can have a Socket.hx class, then a Socket.js.hx , Socket.flash.hx etc for each implementation. Adding @:coreApi to them which would enforce that they respect the Socket.hx API is not yet done but will be soon.

NC

Philippe Elsass

unread,
Apr 15, 2017, 7:27:17 AM4/15/17
to Haxe
What are the rules to choose the file?  Based on target or also custom flags? 

Nicolas Cannasse

unread,
Apr 16, 2017, 3:53:21 AM4/16/17
to haxe...@googlegroups.com
Le 15/04/2017 à 13:27, Philippe Elsass a écrit :
> What are the rules to choose the file? Based on target or also custom
> flags?

Only target for now, this limits the number of file lookups.

Nicolas

Reply all
Reply to author
Forward
0 new messages