Skip to content

Commit

Permalink
Add hl.Bytes.fromNativeArray
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Aug 2, 2024
1 parent 6bd5bd5 commit 26a663d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,11 @@ and eval_expr ctx e =
op ctx (ONullCheck a);
op ctx (OField (r,a,1));
r
| TAbstract ({ a_path = ["hl"],"NativeArray" },[t]) when is_number (to_type ctx t) ->
let a = eval_expr ctx a in
let r = alloc_tmp ctx HBytes in
op ctx (OUnsafeCast(r,a));
r
| t ->
abort ("Invalid array type " ^ s_type (print_context()) t) a.epos)
| "$ref", [v] ->
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/ds/Vector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ abstract Vector<T>(VectorData<T>) {
#else
var a = new Array();
var len = length;
#if (neko)
#if (neko || hl)
// prealloc good size
if (len > 0)
a[len - 1] = get(0);
Expand Down
4 changes: 4 additions & 0 deletions std/hl/Bytes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ package hl;
return untyped $abytes(a);
}

extern public static inline function getNativeArray<T>(a:hl.NativeArray<T>):Bytes {
return untyped $abytes(a);
}

@:from
public static inline function fromBytes(bytes:haxe.io.Bytes) {
return @:privateAccess bytes.b;
Expand Down

0 comments on commit 26a663d

Please sign in to comment.