Neko array indexing

54 views
Skip to first unread message

Edu García

unread,
Jul 5, 2013, 8:11:08 PM7/5/13
to haxe...@googlegroups.com
Can someone explain me why this fails with an "Invalid array access" on Neko? It works correctly on CPP:

var idx:Int = cast(1.5);
trace
(array[idx]);

If I understood that correctly, it should truncate 1.5 to 1 and store it as an Int on idx, and that should be a valid array index value, right?

Thanks!

Franco Ponticelli

unread,
Jul 6, 2013, 1:08:22 AM7/6/13
to haxe...@googlegroups.com
The assumption is wrong. You are using an unsafe cast, that means "I know that the value on the right is of the correct format so don't bother checking it". A typed cast cast(1.5, Int) would on the pther hand, throw an exception. What you are looking for is Sta.int(1.5).

Franco
--
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/groups/opt_out.
 
 

Edu García

unread,
Jul 6, 2013, 1:21:19 AM7/6/13
to haxe...@googlegroups.com
That makes more sense, thanks!
Reply all
Reply to author
Forward
0 new messages