Skip to content

Commit fdcea36

Browse files
committed
refactor(lualib): use builtins for the 5.0 branches instead of a version check
1 parent 4ab5891 commit fdcea36

File tree

6 files changed

+9
-20
lines changed

6 files changed

+9
-20
lines changed

src/LuaLib.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export enum LuaLibFeature {
4545
Generator = "Generator",
4646
InstanceOf = "InstanceOf",
4747
InstanceOfObject = "InstanceOfObject",
48-
IsLua50 = "IsLua50",
4948
Iterator = "Iterator",
5049
LuaIteratorSpread = "LuaIteratorSpread",
5150
Map = "Map",

src/lualib/CountVarargs.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/** @noSelfInFile */
22

3-
import { __TS__IsLua50 } from "./IsLua50";
4-
53
export function __TS__CountVarargs<T>(...args: T[]): number {
64
// select() is not available in Lua 5.0. In that version, the arg table
75
// includes trailing nils.
86
// It is important that the select() branch come first as we need vararg
97
// optimization for this call.
10-
return !__TS__IsLua50 ? select("#", ...args) : args.length;
8+
return select ? select("#", ...args) : args.length;
119
}

src/lualib/IsLua50.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/lualib/Match.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** @noSelfInFile */
22

3-
import { __TS__IsLua50 } from "./IsLua50";
4-
53
export function __TS__Match(s: string, pattern: string, init?: number): LuaMultiReturn<string[]> {
6-
if (__TS__IsLua50) {
4+
if (string.match) {
5+
return string.match(s, pattern, init);
6+
} else {
77
const [start, end, ...captures] = string.find(s, pattern, init);
88
if (start === undefined || end === undefined) {
99
return $multi();
@@ -12,7 +12,5 @@ export function __TS__Match(s: string, pattern: string, init?: number): LuaMulti
1212
} else {
1313
return $multi(...(captures as string[]));
1414
}
15-
} else {
16-
return string.match(s, pattern, init);
1715
}
1816
}

src/lualib/NumberToString.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { __TS__IsLua50 } from "./IsLua50";
2-
31
const radixChars = "0123456789abcdefghijklmnopqrstuvwxyz";
42

53
function modf(this: void, x: number): LuaMultiReturn<[number, number]> {
6-
if (__TS__IsLua50) {
4+
if (math.modf) {
5+
return math.modf(x);
6+
} else {
77
const integral = x > 0 ? Math.floor(x) : Math.ceil(x);
88
return $multi(integral, x - integral);
9-
} else {
10-
return math.modf(x);
119
}
1210
}
1311

src/lualib/SourceMapTraceBack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// TODO: In the future, change this to __TS__RegisterFileInfo and provide tstl interface to
22
// get some metadata about transpilation.
33

4-
import { __TS__IsLua50 } from "./IsLua50";
54
import { __TS__Match } from "./Match";
65

76
interface SourceMap {
@@ -21,7 +20,8 @@ export function __TS__SourceMapTraceBack(this: void, fileName: string, sourceMap
2120
let trace: string;
2221
if (thread === undefined && message === undefined && level === undefined) {
2322
trace = originalTraceback();
24-
} else if (__TS__IsLua50) {
23+
} else if (string.sub(_VERSION, 7, 7) === "0") {
24+
// For Lua 5.0, which doesn't support the thread argument.
2525
trace = originalTraceback(message, level);
2626
} else {
2727
trace = originalTraceback(thread, message, level);

0 commit comments

Comments
 (0)