Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
David
@fayten:matrix.org
[m]

Is it possible to redefine or remove a class in a build macro? I'd like to replace a class with an abstract. E.g.
class Test with abstract Test (Int) to Int.

If explicitly redefining a type is not possible would changing call sights to it be? So instead of standard.module.Test change them to abstract.moduld.Test after Context generation?

Kevin Leung
@kevinresol
You can override a type using -cp
class path that comes later has higher priority
suppose you have src1/foo/Bar.hx and src2/foo/Bar.hx and -cp src1 -cp src2
the latter foo.Bar type will be used
David
@fayten:matrix.org
[m]
I intend on generating the abstract from the class with autoBuild. Any cleaver way I can modify the class path after the generation stage?
Kevin Leung
@kevinresol
basically you cannot modify a type after it is typed
at most you can add some metadata but that won't affect the typing anymore
generally I will use a genericBuild over the type in concern
and create a new type from there
David
@fayten:matrix.org
[m]
Anyway I can replace call sites then? Generate the abstract and put it into a new module then add an import somehow to places that are using the class?
Peter Achberger
@Antriel
Might be able to add that meta from macro and replace the class in genericBuild afterwards.
There's also https://api.haxe.org/haxe/macro/Compiler.html#patchTypes but I've never used that one, not sure how it works.
Kevin Leung
@kevinresol
replace call sites sounds like a code smell
David
@fayten:matrix.org
[m]
I'm sure replacing classes with abstracts is a code smell too xD
Kevin Leung
@kevinresol
maybe you need no-spoon?
https://github.com/back2dos/no-spoon
David
@fayten:matrix.org
[m]
I was looking at no spoon
Specifically it's replace method
Kevin Leung
@kevinresol
what problems are you solving?
no spoon can replace a type, but only before it is being typed
you can't type a type and then replace it
David
@fayten:matrix.org
[m]
So does it need to be called as an init macro?
Kevin Leung
@kevinresol
not sure
perhaps it is better to describe your original problem and see if there are solutions that are not in the minefield area
David
@fayten:matrix.org
[m]

I'm just trying to make some syntactic sugar for some code that will need a quite a few abstracts.
I need a lot of data locality and I can solve this with abstracts by using Abstract(int) to int. Then have the abstract contain static byte arrays for properties. To access an "object" you just specify the proper index.

This route does end up requiring a lot of get_x and set_x functions that just access the underlying arrays. I'd like to generate all of this code from a typedef or class instead. I basically just want to be able to do:
class Point implements Allocator { var x: Int; var y: Int; } and have my crazy abstract made.

Kevin Leung
@kevinresol
I will do this
@:genericBuild(...)
class Allocator<T> {}

typedef Point = Allocator<{x:Int, y:Int}>;
David
@fayten:matrix.org
[m]
Oh interesting
That looks great too
Thanks Kevin, I'll take a look tomorrow. Unortunately I'm off to bed, but I really appreciate the help!
Kevin Leung
@kevinresol
no problem :wink:
David
@fayten:matrix.org
[m]
Well, I was too excited to go to bed. Your suggestion is working beautifully so far. I'll really dig into it tomorrow. 😴
Kevin Leung
@kevinresol
:+1:
Axel Huizinga
@axelhuizinga
Kevin Leung
@kevinresol
it is so that one can contribute with PR :wink:
Axel Huizinga
@axelhuizinga
/**
    @see http://php.net/manual/en/function.gethostname.php
**/
    static function gethostname():String;
how can I do a PR?
Axel Huizinga
@axelhuizinga
done with a fork of the develop branch from the GitHub Desktop which triggered a CI build which failed - do I always have to submit a PR from a new branch of my fork?
Juraj Kirchheim
@back2dos
yeah ... although for trivial changes, you can just click the edit button of the file that interests you: https://github.com/HaxeFoundation/haxe/blob/development/std/php/Global.hx (the pencil icon)
then github will do the fork and pr for you
Juraj Kirchheim
@back2dos
"do I always have to submit a PR from a new branch of my fork?" - not sure I really understand ... you can make the changes on the develop branch of your fork directly, if that's what you're asking ... if you're working on a complex change, it's usually better to branch
Axel Huizinga
@axelhuizinga
Yes that's great but is it intended this automatically triggers a build? as in my attempt https://github.com/HaxeFoundation/haxe/actions/runs/455916883
Juraj Kirchheim
@back2dos
typically, CIs are set up to run a build when a PR is created ... but IIRC when you "edit" a file on GitHub, you don't have to follow through with PR creation, if that's not what you want
Axel Huizinga
@axelhuizinga
I wanted the PR but not trigger the build :)
Juraj Kirchheim
@back2dos
yeah, that's not something you can control ... typically, repo owners configure their CI to trigger a build (and run tests) on PRs to see whether they're safe to merge
serjek
@serjek
is that possible to get fields of typedef at runtime, i.e not using macros?
Juraj Kirchheim
@back2dos
mhh, not really, no
Juraj Kirchheim
@back2dos
you can do Reflect.fields, if that's what you're looking for?
serjek
@serjek
it does not work with typedef, but on the second thought, why I even need it runtime? :D
serjek
@serjek
I started to see following compilation warn, but I have no idea what had changed. what are possible causes of this?
4.1.5/std/haxe/macro/MacroStringTools.hx:89: Warning : This pattern is unused
serjek
@serjek
okay it was improper use of inline.