Created
May 31, 2014 11:04
-
-
Save Zshazz/070949dbe01c7e3b4f93 to your computer and use it in GitHub Desktop.
Two seperate issues I've had with Haxe 3.1.3 thus far...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.rtti.Meta; | |
class MetadataBreak { | |
static public function main() { | |
var mdb = new MetadataBreak(); | |
// OK | |
trace(Meta.getFields(MetadataBreak).test.somedata.length); | |
trace(Meta.getFields(MetadataBreak).test.somedata[0]); | |
var fieldInfo = Reflect.field(Meta.getFields(MetadataBreak), "test"); | |
// Must comment one of the two below lines. | |
trace(fieldInfo.somedata.length); // 1 | |
//trace(fieldInfo.somedata[0]); // 2 | |
// Either individually successfully works. Together they fail with msg | |
// Array access is not allowed on {+ length : Unknown<0> } | |
// To bypass this issue, I've done: | |
trace(fieldInfo.somedata.__a[0]); | |
// which is allowed if and only if you aren't using line 2 | |
// If you use line 2 (fieldInfo.somedata[0]) then it fails with | |
// Cannot access private field __a | |
} | |
public function new() {} | |
@somedata({"a": "b"}, {"c": "d"}) | |
function test() {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
public var fnPtr = function() { } | |
} | |
class B { | |
public var a: A; | |
public function new() { | |
a = new A(); | |
} | |
public function test() { | |
trace(this); | |
} | |
} | |
class ReflectFail { | |
static public function main(): Void { | |
var b = new B(); | |
b.a.fnPtr = b.test; | |
b.test(); | |
b.a.fnPtr(); | |
// Both return: | |
// { a => { fnPtr => #function:-1 } } | |
// which is fine, expected, and useful | |
b.a.fnPtr = Reflect.field(b, "test"); | |
b.a.fnPtr(); | |
// This returns | |
// { fnPtr => #function:0 } | |
// which shows that the "this" reference to b has been lost. | |
// Very non-useful, now. | |
// Ditto with Reflect.getProperty | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment