Problem with getters/setters when compiling to swc.

67 views
Skip to first unread message

Peter Stefcek

unread,
May 15, 2013, 5:58:36 PM5/15/13
to haxe...@googlegroups.com
Hi there guys I have a little problem when targeting swc when it comes to getters/setters. First problem was that everything is made public once compiled which can be easily resolved by specific prefix so users can avoid.

So lets say I have my private variable like this:

private var pv_something:Float;

No to the getter/setter setup obviously the get/set functions we need to specify for haxe will be made public and will work as functions instead as a getter/setter once inside AS3. This was resolved thanks to luce the following way:

#if swc @:extern #end
public var something(get, set):Float;

#if swc @:getter(something) #end
inline private function get_something():Float {
   return pv_something;
}

#if swc @:setter(something) #end
inline private function set_something(p_value:Float):Float {
   return pv_something = p_value;
}

So now the getters look and work like they should inside AS3 envrinment HOWEVER it breaks up the internal code inside haXe compiled code once we are using it in AS3.

Here is an example if I have another method somewhere in the class accessing the getter like this:

private otherMethod():Void {
    if (something == 0) ...
}

This will work in haXe but if we run this through AS3 using the SWC it will throw an error that there is not such method as get_something

Any suggestions? Thanks.

Luca

unread,
May 15, 2013, 6:01:50 PM5/15/13
to haxe...@googlegroups.com
Off the top of my head, the solution is something akin to:

#if swc extern #end public var prop(get,set):T;
#if swc @:getter(prop) #end function get_prop() ....
#if swc @:setter(prop) #end function set_prop(...) ....


when swc is defined, the property as marked as 'extern', so haxe will compile any get/sets as native getter/setter calls, which we have conveneniantly defined the get_prop/set_prop to be.

Peter Stefcek

unread,
May 15, 2013, 6:05:34 PM5/15/13
to haxe...@googlegroups.com
Luca thats what I did in the example atleast I don't see any difference between your and mine code. The problem is that all the internal code seems to break I mean all the calls to the getter inside swc compiled code will crash.with erros like these:

ReferenceError: Error #1069: Property get_something not found on com.example.Test and there is no default value.

P.

Luca

unread,
May 15, 2013, 6:58:12 PM5/15/13
to haxe...@googlegroups.com
Ah sorry, so it is :) I missed the extern on your code.

Perhaps the problem is the getter/setters being inlined? I'm not actively using this, but last I tried a few months ago the combination was working fine.

Cauê Waneck

unread,
May 15, 2013, 7:08:27 PM5/15/13
to haxe...@googlegroups.com
can you try this:

#if swc
@:extern public var prop:T;
#else
public var prop(get,set):T;
#end

Cheers!
Cauê


2013/5/15 Luca <delta...@hotmail.com>
Ah sorry, so it is :) I missed the extern on your code.

Perhaps the problem is the getter/setters being inlined? I'm not actively using this, but last I tried a few months ago the combination was working fine.

--
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.
 
 

Peter Stefcek

unread,
May 15, 2013, 7:42:28 PM5/15/13
to haxe...@googlegroups.com
Hi there guys so I was actually missing the inline on the get/set methods once I added the inline it is no longer looking for them and it runs from AS3. This however still poses a slight problem since now all such getter/setters need to be inlined and therefore unoverridable. Will manage somehow hopefully :)

Thanks
Reply all
Reply to author
Forward
0 new messages