Skip to content

Commit 912a230

Browse files
authored
Add luaTarget: "universal" (#873)
* Add `luaTarget: "universal"` * Add changelog * Add missing dependencies on LuaLibFeature.Unpack * Feedback * `expectTsUnpack` -> `expectLualibUnpack`
1 parent b3b4a21 commit 912a230

File tree

23 files changed

+110
-18
lines changed

23 files changed

+110
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Added new `"luaTarget"` option value - `"universal"`. Choosing this target would make TypeScriptToLua generate code compatible with all supported Lua targets.
6+
- **BREAKING CHANGE:** This is a new default target. If you have been depending on LuaJIT being chosen implicitly, now you have to enable it explicitly with `"luaTarget": "JIT"` in the `tsconfig.json` file.
7+
58
<!-- TODO: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html doesn't seem to work now -->
69

710
- TypeScript has been updated to 3.9. See [release notes](https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/) for details. This update includes some fixes specific to our API usage:

src/CompilerOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export enum LuaLibImportKind {
4444
}
4545

4646
export enum LuaTarget {
47+
Universal = "universal",
4748
Lua51 = "5.1",
4849
Lua52 = "5.2",
4950
Lua53 = "5.3",

src/LuaLib.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export enum LuaLibFeature {
3939
InstanceOfObject = "InstanceOfObject",
4040
Iterator = "Iterator",
4141
Map = "Map",
42+
MathAtan2 = "MathAtan2",
4243
New = "New",
4344
Number = "Number",
4445
NumberIsFinite = "NumberIsFinite",
@@ -68,12 +69,16 @@ export enum LuaLibFeature {
6869
Symbol = "Symbol",
6970
SymbolRegistry = "SymbolRegistry",
7071
TypeOf = "TypeOf",
72+
Unpack = "Unpack",
7173
}
7274

7375
const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
7476
ArrayFlat: [LuaLibFeature.ArrayConcat],
7577
ArrayFlatMap: [LuaLibFeature.ArrayConcat],
7678
Error: [LuaLibFeature.New, LuaLibFeature.Class, LuaLibFeature.FunctionCall],
79+
FunctionApply: [LuaLibFeature.Unpack],
80+
FunctionBind: [LuaLibFeature.Unpack],
81+
FunctionCall: [LuaLibFeature.Unpack],
7782
Generator: [LuaLibFeature.Symbol],
7883
InstanceOf: [LuaLibFeature.Symbol],
7984
Iterator: [LuaLibFeature.Symbol],
@@ -82,7 +87,7 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
8287
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
8388
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
8489
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
85-
Spread: [LuaLibFeature.Iterator],
90+
Spread: [LuaLibFeature.Iterator, LuaLibFeature.Unpack],
8691
SymbolRegistry: [LuaLibFeature.Symbol],
8792
};
8893

src/lualib/FunctionApply.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function __TS__FunctionApply(this: void, fn: (this: void, ...args: any[]) => any, thisArg: any, args?: any[]): any {
22
if (args) {
3-
return fn(thisArg, (unpack || table.unpack)(args));
3+
return fn(thisArg, ...args);
44
} else {
55
return fn(thisArg);
66
}

src/lualib/FunctionBind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ function __TS__FunctionBind(
88
for (let i = 0; i < boundArgs.length; ++i) {
99
table.insert(args, i + 1, boundArgs[i]);
1010
}
11-
return fn(thisArg, (unpack || table.unpack)(args));
11+
return fn(thisArg, ...args);
1212
};
1313
}

src/lualib/FunctionCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function __TS__FunctionCall(this: void, fn: (this: void, ...args: any[]) => any, thisArg: any, ...args: any[]): any {
2-
return fn(thisArg, (unpack || table.unpack)(args));
2+
return fn(thisArg, ...args);
33
}

src/lualib/MathAtan2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const __TS__MathAtan2 = math.atan2 || math.atan;

src/lualib/Spread.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ function __TS__Spread<T>(this: void, iterable: string | Iterable<T>): T[] {
1010
arr[arr.length] = item;
1111
}
1212
}
13-
return (table.unpack || unpack)(arr);
13+
return __TS__Unpack(arr);
1414
}

src/lualib/Unpack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const __TS__Unpack = table.unpack || unpack;

src/lualib/declarations/math.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
declare namespace math {
33
/** @tupleReturn */
44
function modf(x: number): [number, number];
5+
6+
function atan(x: number): number;
7+
// eslint-disable-next-line @typescript-eslint/unified-signatures
8+
function atan(y: number, x?: number): number;
9+
10+
function atan2(y: number, x: number): number;
511
}

0 commit comments

Comments
 (0)