Skip to content

Commit

Permalink
Merge pull request #42 from xoofx/fix-vector-args
Browse files Browse the repository at this point in the history
Fix argument passing for vector types
  • Loading branch information
xoofx authored Sep 11, 2023
2 parents 01995df + e8af27a commit 22fb1f0
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ private T ToArg<TBase, T>(int argIndex, object value, int align = 0) where T : u
if (value is KalkVector vec)
{
var span = vec.AsSpan();
var minSize = Math.Min(targetSize, span.Length);
span = span.Slice(0, minSize);
if (span.Length != targetSize)
{
throw new ScriptArgumentException(argIndex, $"Invalid size ({BytesToString(span.Length)}) for input vector `{vec.TypeName}`. Expecting {dimension} elements with {BytesToString(baseElementSize)} per element (with a total size of {BytesToString(targetSize)}).");
}
span.CopyTo(MemoryMarshal.Cast<TBase, byte>(elements));
}
else
Expand All @@ -193,6 +195,8 @@ private T ToArg<TBase, T>(int argIndex, object value, int align = 0) where T : u
return Unsafe.As<TBase, T>(ref elements[0]);
}
}

private static string BytesToString(int size) => size == 1 ? $"{size} byte" : $"{size} bytes";

private object ToResult<TBase, T>(T result) where T: unmanaged where TBase: unmanaged
{
Expand Down

0 comments on commit 22fb1f0

Please sign in to comment.