Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lualib/5.0/SparseArraySpread.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { __TS__SparseArray } from "./SparseArray";
import { __TS__Unpack } from "./Unpack";

export function __TS__SparseArraySpread<T>(this: void, sparseArray: __TS__SparseArray<T>): LuaMultiReturn<T[]> {
return unpack(sparseArray, 1, sparseArray.sparseLength);
return __TS__Unpack(sparseArray, 1, sparseArray.sparseLength);
}
17 changes: 16 additions & 1 deletion src/lualib/5.0/Unpack.ts
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
export const __TS__Unpack = unpack;
/** @noSelfInFile */

// We're not interested in emulating all of the behaviors of unpack() from Lua
// 5.1, just the ones needed by other parts of lualib.
export function __TS__Unpack<T>(list: T[], i: number, j?: number): LuaMultiReturn<T[]> {
if (i === 1 && j === undefined) {
return unpack(list);
} else {
j ??= list.length;
const slice: T[] = [];
for (let n = i; n <= j; n++) {
slice[n - i] = list[n - 1]; // We don't want to add 1 to the index into list.
}
return $multi(...slice);
}
}
3 changes: 0 additions & 3 deletions src/lualib/declarations/tstl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ interface LuaClassInstance extends LuaMetatable<any> {
constructor: LuaClass;
}

// Declare unpack for versions that have it instead of table.unpack
declare const unpack: typeof table.unpack | undefined;

// Declare math atan2 for versions that have it instead of math.atan
declare namespace math {
const atan2: typeof atan;
Expand Down
4 changes: 4 additions & 0 deletions src/lualib/declarations/universal/unpack.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @noSelfInFile */

// Declare unpack for versions that have it instead of table.unpack
declare const unpack: typeof table.unpack | undefined;