haxe

How to look for a class type in an array using generics

元气小坏坏 提交于 2019-12-11 04:22:13
问题 I'd like to look for a specific class type into an array. No clue how. var a:A = new A(); var b:B = new B(); // B extends A var c:C = new C(); // C extends A var arr:Array<A> = []; arr.push(a); arr.push(b); arr.push(c); // i'd like something like: c = arr.get<C>(); 回答1: In Haxe, like Java, you can't get access to the type parameter inside the code, since in most implementations it is erased, meaning the same as "Dynamic". This means that in order to implement that, you'd need a function like

How do I resolveClass without importing the type first?

给你一囗甜甜゛ 提交于 2019-12-11 03:21:17
问题 Note that I'm using Haxe 3.0.1 on Linux targeting Neko. Consider the following code: var classObject = Type.resolveClass("Foo"); Assuming that I have a class Foo in the same package as this code, this should give me a Class object with info about Foo in it. However, in my tests it is only working if I import Foo; first. If I do not import Foo then resolveClass returns null instead. This is strange to me. I noticed that the Haxe API docs state: The class must have been compiled to be

Specifing file encoding while reading a file with sys.io.File.read in Haxe

一笑奈何 提交于 2019-12-11 02:59:27
问题 I know how to read a file with Haxe by using sys.io.File.read (compare Reading lines from a file in Haxe and I also know that the sys module is not available for each target). However how can I tell sys.io.File.read that my text file is encoded via a certain encoding (e.g. UTF-16, UTF-8, ISO-8859-1, ...)? 回答1: There is no way to do this at File -level, but you can encode / decode the String after reading the file. For instance, Utf8.encode() will convert a ISO-8859-1 string to a UTF-8 string:

How to properly install and set up Flambe?

纵然是瞬间 提交于 2019-12-11 02:58:19
问题 I have followed the instructions here, created a new project and tried to run it but all I got was a black web page. I'm not sure if the build command worked properly (I've never done it before). Then I tried downgrading haxe to 3.1.3 and reinstall Flambe, like mentioned here. I still get a black page when trying to run the project. Here is the result of using the build command in console (after the downgrade): Building: build/web haxe -main urgame.Main -lib flambe -cp src -dce full -debug -

Haxe: define a function/macro which fires when an object goes out of scope?

喜欢而已 提交于 2019-12-11 02:53:05
问题 Is this possible in Haxe to have the compiler automatically insert a function call / code segment at the point where an object instance goes out of scope? I have object instances that require manual cleanup beyond what garbage collection does (for the JS target). More Info I'm experimenting with allocating small data structures in JavaScript code manually inside a virtual heap (an ArrayBuffer ), similar to what is done with compiled asm.js programs. I am using Haxe in part because I can

haxe “should be int” error

吃可爱长大的小学妹 提交于 2019-12-11 02:32:09
问题 Haxe seems to assume that certain things must be Int . In the following function, class Main { static function main() { function mult_s<T,A>(s:T,x:A):A { return cast s*x; } var bb = mult_s(1.1,2.2); } } I got (with Haxe 3.01): Main.hx:xx: characters 48-49 : mult_s.T should be Int Main.hx:xx: characters 50-51 : mult_s.A should be Int Can anyone please explain why T and A should be Int instead of Float ? A more puzzling example is this: class Main { public static function min<T:(Int,Float)>(t:T

Test multiple Haxe target languages with a single script

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:12:41
问题 In Haxe, is there any script or command that can automatically run a Haxe program in multiple target languages? I'd like to write a script that does the following: 1) Compile Haxe source code to JavaScript, C++, PHP, and Java. 2) Display the output of the Haxe program in each target language. 回答1: You can do this with normal hxml, and a special js runtime that lets you output to the terminal. I'm using phantomjs, but other environments like node.js are possible. Note that I need to add append

Pass arguments to a delayed function with Haxe

旧城冷巷雨未停 提交于 2019-12-10 23:28:56
问题 Do you know if there is an easy way to pass some arguments to a function called via haxe.Timer.delay(func, delay); By "easy" I mean without creating any custom timer. 回答1: You can use bind() for this. For example, if you want to call someFunction("abc") : haxe.Timer.delay(someFunction.bind("abc"), 1000); // 1s Prior to Haxe 3, you could use callback: haxe.Timer.delay(callback(someFunction,"abc"), 1000); // 1s 回答2: Everything can be achieved with an extra level of indirection :-) It seems like

Lambda iteration over an Iterator (not an Iterable)

时光毁灭记忆、已成空白 提交于 2019-12-10 22:34:02
问题 I often read it's impossible to call Lambda functions on iterators. And I lived in that belief until now. However reading the book Professional Haxe by Franco Ponticelli and Lee-McColl-Sylvester about what makes an objet an Iterable or an Iterator made me think of one trick, that seems to work; at least in the simple case I just tested. The trick is simply to declare an iterator() function inside the Iterator class, returning itself (weird yes, but not that incoherent). I don't know if this

Why is this Haxe try-catch block still crashing, when using Release mode for C++ target

北慕城南 提交于 2019-12-10 18:22:30
问题 I have a HaxeFlixel project, that is working OK in Debug mode for misc targets, including flash, neko and windows. But Targeting Windows in Release mode , I'm having an unexpected crash, and surprisingly it's happening inside a try-catch block. Here's the crashing function: /** * Will safely scan a parent node's children, search for a child by name, and return it's text. * @param parent an Fast object that is parent of the `nodeNamed` node * @param nodeName the node's name or a comma