Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Emugel
@emugel
he said (again) "don't underestimate java"
Emugel
@emugel
if I understood correctly you can draw a parallel between 1. java and hashlink/C and 2. jvm and hashlink/vm. One runs fast and compiles slowly, the other runs slowler and compiles very fast
Peter Achberger
@Antriel
I don't think that's correct. java is simply a Java output that needs to be compiled into something JVM can run. Whereas jvm target goes there directly. Which is faster to compile, and also possibly faster to run, as there could be optimizations that aren't doable from the Java code.
Although iirc in that video he talked about which approach works better in which circumstances, as the JVM target isn't optimized entirely yet.
In either case hashlink/C vs vm one is not a good analogy. VM will be JIT I think, whereas C won't, as it doesn't need to be. With JAVA it's always just VM, there's no native compilation anywhere.
Kevin Bloch
@kevin.bloch_gitlab
Interesting! It seems it was true about run-time performance...I'm not sure which video I watched yesterday, but it was from a pre-4-release time, and there the speaker had claimed that the JVM target was faster both at compile time and at run-time. Maybe that was incorrect or maybe things have changed since then as the feature was worked on further. Thanks for pointing to the new video ( https://haxe.org/videos/conferences/haxeup-sessions-2019/simon-krajewski-haxe-status-report.html if anyone's looking for this later ) OK, good to know...thanks, everyone! :)
Peter Achberger
@Antriel
It should be faster, just maybe not in everything yet, but eventually it should be at least as fast or faster.
It's basically skipping the .java abstraction layer and going directly to bytecode.
Kevin Bloch
@kevin.bloch_gitlab
:+1:
Emugel
@emugel
thanks @Antriel ! yes I think it makes more sense like that
Emugel
@emugel
In my 2 lines notes about that part I wrote " -D jvm produces a .jar with .class bytecode. No need for javac = much faster compilation time", I think I misunderstood javac. So if I understand what you said with -D jvm it should skip the step of producing the java sources, directly writing java bytecode
hence the part about the 'Waneck functions', apparently they're a mess but provide some optimizations not yet available with -D jvm
Peter Achberger
@Antriel
Yeah, that's it.
Mel Massadian
@melMass

Hi, I'm having a hard time wraping my head around enum abstracts use cases.
With this simple example:

enum abstract EConfiguration(String) from String to String{
    var Debug;
    var Shipping;
    var Test;
}

I want to be able to do:

var config:EConfiguration = "Debug";

Which works, but the following works aswel...:

var config:EConfiguration = "Debugtypo";

How can I restrict it to declared fields, throwing on value error ?

Kevin Leung
@kevinresol
You can remove from String and use a custom @:from cast to check the values
Peter Achberger
@Antriel
I just want to add that such approach is only useful if you have input unknown-at-compile-time and indeed want to check it for validity. If you just want to use it as Enum, and for some reason need it to be String, var config:EConfiguration = Debug; will work best. Without using from String.
Mel Massadian
@melMass
@kevinresol Thanks I thought it was just an alternate way to do the same thing !
@Antriel Yep it's the former, runtime string -> valid enum
Kevin Leung
@kevinresol
@melMass it is not the same
Mel Massadian
@melMass
@kevinresol Thanks, I'm not sure what do to in the @:from function to check for valid enum to be honest 🙈
Kevin Leung
@kevinresol
I usually write this:
@:from static function fromString(v:String):EConfiguration {
  return switch v {
    case Debug | Shipping | Test: cast v;
    case _: throw 'error';
  }
}
Mel Massadian
@melMass
<3 Thanks it works as expected
Emugel
@emugel
Any idea/recipe how in unit test to easily test whether a return is equal to certain AST? The enum can contain some Array, e.g. Alt([Seq([Text("Bla"), Opt([Text("Bla")])])]) (not sure if this is even correct ^^). Or should I write something from scratch?
hum I wonder if switch case would not be enough
how to write unit tests for simple AST parsers would be the underlying question I guess
Juraj Kirchheim
@back2dos
pattern matching is probably the easiest way to go
or you make a printer for your AST and then you compare expected vs actual string representation
Emugel
@emugel
alright! yes I tried with pattern matching already and it seems the easiest, at least if there is no error
Axel Huizinga
@axelhuizinga
anyone used d3 time format?
var formatTime = D3.time.format;
compiles but gives the runtime error:
TypeError: d3.time is undefined Charts.hx:229
Philippe
@elsassph
How do you import D3?
Makhor
@Makhor
Hey there! Has anyone gotten a Json parser error: invalid char 0 at position 0 when compiling the hxelectron demo? I'm using haxe 4.0.3, and I am not exactly sure how I could fix this issue.
gdeverlant
@gdeverlant
greetings
How can i compile this library https://lib.haxe.org/p/crypto/
for Actionscript ?
as a SWC
Danny Yaroslavski
@dyarosla
Hey all! I recently upgraded to Unity 2019 and can’t seem to get my Haxe CS builds working - anyone have an up to date unity hello world HXML setup?
Danny Yaroslavski
@dyarosla
Nvm- same setup works just realized I was getting conflicts because CS files were being generated at the root name space. Debug flag no_root was all that was needed in the hxml.
Danny Yaroslavski
@dyarosla
What would be the best way to write Haxe code that, if compiling to cs, uses cs.NativeArray but if compiling to any other target else uses the regular Array? Ideally without having to surround each instance of where this is needed with #if's?
Kevin Leung
@kevinresol
you can wrap it with an abstract
Danny Yaroslavski
@dyarosla
how so
would i create an abstract array type that wraps overtop of a conditionally compiled array ?
Kevin Leung
@kevinresol
something like this
private typedef Impl<T> = #if cs cs.NativeArray<T> #else Array<T> #end;
abstract MyArray<T>(Impl<T>) {
  public inline function new() this = #if cs new cs.NativeArray() #else new Array() #end;
  public inline function push(v:T):Int return #if cs this.Add(v) #else this.push(v) #end;
}
Danny Yaroslavski
@dyarosla
Yea that's what I imagined you'd meant
Looks like I'll prob be going down this road then- really want performance in this particular bit of code and CS target currently creates Array<object> for any type, boxing and unboxing things. Whereas if you use NativeArray it doesn't do that.
Thank you so much @kevinresol ! You're a lifesaver once again!
Édouard Lopez
@edouard-lopez

Hello,
I've JSON data, that contains a questions with 2 items that look similar but whom options and answer field vary depending on type.

    "questions": [{
        "type": "qcm",
        "options": ["Product 1", "Product 2", "Product 3"],
        "answer": [false, false, false,]
    }, {
        "type": "numeric",
        "options": null,
        "answer": 546
    }]

How can I model those 2 types of question using typedef?

So far I did:

typedef Questionnaire = {
    survey:Survey,
    questions:Array<Question_Choix_Multiple, Question_Numeric>,
}

But then I got

src/Main.hx:28: characters 12-60 : Invalid number of type parameters for Array
Kevin Leung
@kevinresol
you can use tink_json to parse them into enums
the result will be something like this:
enum Question {
  Qcm(options:Array<String>, answer:Array<Bool>);
  Numeric(options:Null<Any>, answer:Int);
}
Here is the compilable code (with -lib tink_json)
class Main {
  static function main() {
    var json = '{  "questions": [{
        "type": "qcm",
        "options": ["Product 1", "Product 2", "Product 3"],
        "answer": [false, false, false]
    }, {
        "type": "numeric",
        "options": null,
        "answer": 546
    }]}';

    var result:Obj = tink.Json.parse(json);

    trace(result.questions[0]);
    trace(result.questions[1]);
  }

}

typedef Obj = {
  questions:Array<Question>,
}

enum Question {
  @:json({'type': 'qcm'}) Qcm(options:Array<String>, answer:Array<Bool>);
  @:json({'type': 'numeric'}) Numeric(options:Null<String>, answer:Int);
}