Accessing a typedef in a different source file?

79 views
Skip to first unread message

Craig Kaplan

unread,
Mar 14, 2014, 11:50:27 AM3/14/14
to haxe...@googlegroups.com
I'm encountering strange behaviour with typedefs, and I wanted to check if I'm missing something obvious.  I'd like to define a typedef in a source file, and have that typedef accessible from multiple other files that use it.  Is that possible?

Here's a simple example, spread over two files, which distills out the behaviour I'm seeing:

--------- Thing.hx ---------
package;

typedef MyList = List<Int>;

class Thing { public function new() {} }
----------------------------------

------------ Main.hx -----------
package;

class Main {
public function new () {
var t = new Thing();
var a = new MyList();
}
}
--------------------------------------

As written, this program gives me "Class not found : MyList" at compilation time.  That makes me think that Main.hx can't even see MyList.  But that's not quite true, because if I add a copy of the typedef to Main.hx, I instead get "Type name MyList is redefined from module Main".

So -- what am I missing here?  Is there some Haxe best practice that lets me define a typedef in one place and have it accessible everywhere?

Thanks.

Simon Krajewski

unread,
Mar 14, 2014, 11:53:03 AM3/14/14
to haxe...@googlegroups.com
You have to either import Thing or use the fully qualified name Thing.MyList.

Simon

Andreas Mokros

unread,
Mar 14, 2014, 11:54:50 AM3/14/14
to haxe...@googlegroups.com
Hi.

On Fri, 14 Mar 2014 08:50:27 -0700 (PDT)
Craig Kaplan <azr...@gmail.com> wrote:
> So -- what am I missing here?

Either:
import Thing;
or:
var a = new Thing.MyList();

--
Mockey

Craig Kaplan

unread,
Mar 14, 2014, 11:56:21 AM3/14/14
to haxe...@googlegroups.com
That's perfect.  Thanks!

Andreas Mokros

unread,
Mar 14, 2014, 11:56:34 AM3/14/14
to haxe...@googlegroups.com
Hi.

On Fri, 14 Mar 2014 16:54:50 +0100
Andreas Mokros <m...@medienpensionat.com> wrote:
> Either:
> import Thing;
> or:
> var a = new Thing.MyList();

Way too slow, sorry.

--
Mockey
Reply all
Reply to author
Forward
0 new messages