@:structInit
@:publicFields
class State {
var a:Int;
var b:Array<String>;
var c:Float;
var d:Test;
var e:Int;
var f:Int;
var g:Int;
var h:Int;
var i:Array<Int>;
}
class Test {
public function new() {
}
public function x() {
var a = Main.state.a;
var b = Main.state.b;
var c = Main.state.c;
var d = Main.state.d;
var e = Main.state.e;
var f = Main.state.f;
var g = Main.state.g;
var h = Main.state.h;
var i = Main.state.i;
trace( 'a', a );
trace( 'b', b );
trace( 'c', c );
trace( 'd', d );
trace( 'e', e );
trace( 'f', f );
trace( 'g', g );
trace( 'h', h );
// trace( 'i', i ); // this kills hl
}
public function foo() {
trace( this );
}
}
class Main {
public static var state:State;
static var d:Test;
static function main() {
d = new Test();
state = {
a: 1,
b: [ "Hello", "world" ],
c: 3.14,
d: d,
e: 333,
f: 444,
g: 555,
h: 666,
i: [ 1, 2, 3, 4, 5, 6 ]
};
dododo();
}
static function dododo() {
state.d.foo();
d.x();
}
}
output
Main.hx:42: #Test
Main.hx:30: a, 1
Main.hx:31: b, [Hello,world]
Main.hx:32: c, 3.14
Main.hx:33: d, #Test
Main.hx:34: e, 333
Main.hx:35: f, 333
Main.hx:36: g, 333
Main.hx:37: h, 333
Works on neko. Uncommenting trace of i makes hl crash with MAV. Adding constructor to State manually makes it work.
Test.foo() function is there because it’s actually possible to change this of Test to one of an array (or maybe even to integer) but I’m yet not sure how, and didn’t manage to make it work in this example.