-
-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ByteArray
compatible with Haxe's Bytes
class.
#2692
Conversation
With one exception for the time being.
I spent at least an hour trying to figure out why it wasn't the same as `_length`. Hopefully this comment can save the next person that trouble. For background information, see https://en.wikipedia.org/wiki/Dynamic_array.
Whoops, a9c080e is counterproductive. I was trying to bypass the overridden |
a9c080e
to
0e1d832
Compare
This PR has to be merged before openfl/lime#1765. I made sure that this is compatible with either version of Lime; even if we never merged that one, this shouldn't break anything. If it did break anything, it would only be for OpenFL-JS users, not regular OpenFL users. And only if the OpenFL-JS users were messing around with non-public APIs. |
I did a quick test with openfl-js, and this breaks the The following JS code should print 0 to the console three times. It worked previously, but with your changes, it throws an exception. var bytes = new openfl.utils.ByteArray();
bytes.length = 3;
for (let i = 0; i < 3; i++)
{
console.log(bytes.readByte());
} While |
I guess that explains why it was added. I'll see if I can work out another option. |
Ok, how's this look? |
I get the following errors with when building openfl-js (using Lime 8.1.1):
|
It looks like the openfl-js length property will need to be defined with methods that have a name that doesn't conflict with
private function get_length2():Int
{
return __length;
}
private function set_length2(value:Int):Int
{
return (this : ByteArray).length = value;
} Then, it looks like public function readUnsignedByte():Int
{
if (position < __length)
{
return get(position++);
}
else
{
throw new EOFError();
return 0;
}
} So maybe if all of the other read/write methods use |
This is only temporarily necessary, to avoid the getter Lime adds to `haxe.io.Bytes`. Once that's removed, it would be safe to revert this.
These `#if openfljs` cases can be deleted once Lime stops shadowing `haxe.io.Bytes`.
Whoops, not sure how I missed that. Guess I forgot Lime declared In any case, this should fix it. |
Currently, Lime shadows
haxe.io.Bytes
, but we might not have to. I'm trying to rewrite any piece of code that references the shadowed version of the class to refer to the original version instead.ByteArrayData
is one such piece of code. It includes lots of references to the private variablel
, which only exists in Lime's version of the class.For whatever reason, openfl-js wants
length
to be a property with a getter and setter. But it also wants to be able to bypass those accessors. But it also doesn't want to use Haxe's accessors that can be bypassed using@:bypassAccessor
; it callsObject.defineProperties()
at runtime. So it stores the value inl
, and usesl
when it wants to bypass the accessors.It all works, of course. But I can't seem to find any reason for any of it.
ByteArray
is the public API for all this, and it defines a perfectly functional getter and setter. There's no need forByteArrayData
to have its own setter on top of that. Is there? (I'll admit I've never actually used openfl-js, but I did make sure it still compiles after these changes.)