-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
RawArray needs a slicing operation #5701
Comments
If adding a bind isn't too tricky a process I could try to add this to a fork and go through the PR process. Edit: It looks tedious. Trying a grep on the sources for RawArray didn't find any of the implementation functions. Must be using templates. |
@gau-veldt I think it was named ByteArray on the C++ side (or it is part of DVector) |
I need more information about where I should be looking in the sources to add this method to RawArray since I can't even find the implementations of the currently defined methods E.g.: RawArray.append() |
That should be enough to start. |
Actually I think it's already there since I've seen ByteArray.subarray in the code which is basically what a .slice() method would be doing. The only problem is subarray() returns the same array (at different pointers) this is likely not safe to use as-is in a naive bind for GDScript since the following code would cause trouble:
For GDScript it is likely required to make a copy of the subarray to be safe, requiring additional code for the GDScript implementation specifically, not the DVector template. |
okay I do have to make my owqn subarray method on DVector since the subarray I spotted in the code was actually from the java portion, |
Hopefully this won't be too ugly an implementation:
|
If this is OK I can then attempt to do the bind for PS: I've kept the name from |
It's in my github fork guess I need to do a PR and reference this issue. PR is #5765 |
The PR includes documentation of the method in classes.xml as well as handling of -1 to mean 'last element'. |
I think the merging of #5879 closes this one. |
Operating system or device - Godot version:
Godot v2.1.beta
Issue description (what happened, and what was expected):
RawArray supports adding chunks onto the end but missed an operation to obtain a copied slice of a larger RawArray to a new (smaller) RawArray. Of course this could be done in a loop but things like that may be a bit inefficient doing in script, especially for larger RawArray's. C++ optimized assembly FTW.
Proposed prototype (-1 means end of the array):
RawArray RawArray.slice(start,end=-1)
Copies a slice of the original RawArray and returns a new RawArray containing the subsection, from start to end (or -1 to slice to the end).
The text was updated successfully, but these errors were encountered: