static inline refering another static inline?

80 views
Skip to first unread message

Mark

unread,
Sep 16, 2014, 8:15:07 AM9/16/14
to haxe...@googlegroups.com
hi Guys,

I'm curious about your point. Especially Nicolas/Haxe-devs - do you agree or disagree?

I was trying to do this:

private static inline var foo      : Int = 100;
private static inline var uncleFoo : Int = foo * 100;

Which resulted in:
Source/Whatever.hx:00: characters XX-YY : Inline variable initialization must be a constant value

I would find it a great feature if this would be allowed, i.e. constant variable's value "declared" based on another constant.

What do you think?


Thanks for the feedback,
Mark

Simon Krajewski

unread,
Sep 16, 2014, 8:17:20 AM9/16/14
to haxe...@googlegroups.com
What Haxe version is that? Works for me: http://try.haxe.org/#9389c

Simon

Mark

unread,
Sep 16, 2014, 9:00:56 AM9/16/14
to haxe...@googlegroups.com
Oups, I made a mistake here, it's not about primitives at all. Silly me, sorry :)

Here's what I actually meant:

private static inline var myStaticPoint : Point = new Point (10, 10);

or even:
private static inline var foo : Int = 100;
private static inline var myStaticPoint2 : Point = new Point (foo, foo * 5);


So the same thing I can do with another class, String:

private static inline var strFoo : String = "my const text";

Simon Krajewski

unread,
Sep 16, 2014, 9:03:08 AM9/16/14
to haxe...@googlegroups.com
Am 16.09.2014 15:00, schrieb Mark:
Oups, I made a mistake here, it's not about primitives at all. Silly me, sorry :)

Here's what I actually meant:

private static inline var myStaticPoint : Point = new Point (10, 10);

or even:
private static inline var foo : Int = 100;
private static inline var myStaticPoint2 : Point = new Point (foo, foo * 5);

Inlining that was previously allowed but would lead to surprising results because usage of the variable would create a new instance on each access. That's why it was forbidden in Haxe 3.

Simon

Mark

unread,
Sep 16, 2014, 9:16:01 AM9/16/14
to haxe...@googlegroups.com
My assumption was a copy gets created (ie static variable) when parent class is instanciated. Not on global stack, not even if many classes use the same values - just for the parent's lifecycle.

What you say sounds like a bug to me. Might be a good short-term solution to remove the feature, though.

Thank you for the feedback.

Sam MacPherson

unread,
Sep 16, 2014, 1:45:57 PM9/16/14
to haxe...@googlegroups.com
The result makes sense to me. You are inlining "new Point(10, 10)" where ever you reference myStaticPoint2. It would make a lot more sense in most (all?) cases to remove the inline from that declaration because a variable access is likely to be faster than instantiating a new object each time.

Benjamin Dubois

unread,
Sep 16, 2014, 4:35:57 PM9/16/14
to haxe...@googlegroups.com
while I was asking
What was working in haxe 2 doesn't work anymore :
public static inline var ZERO : V2D = new V2D(0, 0);

I get this error :
Variable initialization must be a constant value​
​.

How do I initialize static inline variable with an object (which is actually constant) ? ​

A guy told me once
if it's a constant it's not an inline:
public static var ZERO(default,never) : V2D = new V2D(0, 0);

--
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/d/optout.

Mark

unread,
Sep 17, 2014, 4:05:59 AM9/17/14
to haxe...@googlegroups.com
[OFF: Your last name is very famous which makes me jealous (MacPherson strut, the car suspension - still the best IMHO and used in many car models) :) ]

The thing is, I don't want the inline object to be created every time it is referenced. Like I said, it probably was a bug in haxe2 (or an imperfect approach, perhaps?).

But instead, by 'inline' get the code of class (e.g. ...geom.Point.hx) injected into my code.

The question is, could that speed up my application at the end of the day (I don't know how haxe precompiler & compiler works) or not? I don't know this.

If it does, IMHO it would be a good feature, at least for objects that are close to primitives, like Point.hx or Rectangle.hx or Random.hx.
Reply all
Reply to author
Forward
0 new messages