Skip to content

Commit d009f69

Browse files
committed
Move lua types in lualib to declarations directory
1 parent aa32a5c commit d009f69

24 files changed

+75
-125
lines changed

src/LuaTransformer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5086,7 +5086,13 @@ export class LuaTransformer {
50865086
return tstl.createCallExpression(tstl.createIdentifier("tostring"), [expression]);
50875087
}
50885088

5089-
protected expressionPlusOne(expression: tstl.Expression): tstl.BinaryExpression {
5089+
protected expressionPlusOne(expression: tstl.Expression): tstl.Expression {
5090+
if (tstl.isNumericLiteral(expression)) {
5091+
const newNode = tstl.cloneNode(expression);
5092+
newNode.value++;
5093+
return newNode;
5094+
}
5095+
50905096
if (tstl.isBinaryExpression(expression)) {
50915097
expression = tstl.createParenthesizedExpression(expression);
50925098
}

src/lualib/ArrayConcat.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare function pcall(this: void, func: () => any): any;
2-
declare function type(this: void, val: any): string;
3-
41
function __TS__ArrayConcat(this: void, arr1: any[], ...args: any[]): any[] {
52
const out: any[] = [];
63
for (const val of arr1) {

src/lualib/ArrayShift.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare namespace table {
2-
function remove<T>(this: void, arr: T[], idx: number): T;
3-
}
41
function __TS__ArrayShift<T>(this: void, arr: T[]): T {
52
return table.remove(arr, 1);
63
}

src/lualib/ArraySort.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare namespace table {
2-
function sort<T>(this: void, arr: T[], compareFn?: (this: void, a: T, b: T) => boolean): void;
3-
}
41
function __TS__ArraySort<T>(this: void, arr: T[], compareFn?: (a: T, b: T) => number): T[] {
52
if (compareFn !== undefined) {
63
table.sort(arr, (a, b) => compareFn(a, b) < 0);

src/lualib/ArrayUnshift.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare namespace table {
2-
function insert<T>(this: void, arr: T[], idx: number, val: T): void;
3-
}
41
function __TS__ArrayUnshift<T>(this: void, arr: T[], ...items: T[]): number {
52
for (let i = items.length - 1; i >= 0; --i) {
63
table.insert(arr, 1, items[i]);

src/lualib/ClassIndex.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
interface LuaClass {
2-
____super?: LuaClass;
3-
____getters?: { [key: string]: (this: void, self: LuaClass) => any };
4-
}
5-
6-
declare function rawget<T, K extends keyof T>(this: void, obj: T, key: K): T[K];
7-
8-
function __TS__ClassIndex(this: void, classTable: LuaClass, key: keyof LuaClass): any {
1+
function __TS__ClassIndex(this: void, classTable: LuaClass, key: any): any {
92
while (true) {
103
const getters = rawget(classTable, "____getters");
114
if (getters) {

src/lualib/ClassNewIndex.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
interface LuaClass {
2-
____super?: LuaClass;
3-
____setters?: { [key: string]: (this: void, self: LuaClass, val: any) => void };
4-
}
5-
6-
declare function rawget<T, K extends keyof T>(this: void, obj: T, key: K): T[K];
7-
declare function rawset<T, K extends keyof T>(this: void, obj: T, key: K, val: T[K]): void;
8-
9-
function __TS__ClassNewIndex(this: void, classTable: LuaClass, key: keyof LuaClass, val: any): void {
1+
function __TS__ClassNewIndex(this: void, classTable: LuaClass, key: any, val: any): void {
102
let tbl = classTable;
113
do {
124
const setters = rawget(tbl, "____setters");

src/lualib/FunctionApply.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
declare function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
2-
3-
declare namespace table {
4-
export function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
5-
}
6-
7-
type ApplyFn = (this: void, ...argArray: any[]) => any;
8-
9-
function __TS__FunctionApply(this: void, fn: ApplyFn, thisArg: any, argsArray?: any[]): any {
10-
if (argsArray) {
11-
return fn(thisArg, (unpack || table.unpack)(argsArray));
1+
function __TS__FunctionApply(
2+
this: void,
3+
fn: (this: void, ...args: any[]) => any,
4+
thisArg: any,
5+
args?: any[]
6+
): any {
7+
if (args) {
8+
return fn(thisArg, (unpack || table.unpack)(args));
129
} else {
1310
return fn(thisArg);
1411
}

src/lualib/FunctionBind.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
declare function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
2-
3-
declare namespace table {
4-
export function insert<T>(this: void, t: T[], pos: number, value: T): void;
5-
6-
export function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
7-
}
8-
9-
type BindFn = (this: void, ...argArray: any[]) => any;
10-
11-
function __TS__FunctionBind(this: void, fn: BindFn, thisArg: any, ...boundArgs: any[]): (...args: any[]) => any {
12-
return (...argArray: any[]) => {
1+
function __TS__FunctionBind(
2+
this: void,
3+
fn: (this: void, ...argArray: any[]) => any,
4+
thisArg: any,
5+
...boundArgs: any[]
6+
): (...args: any[]) => any {
7+
return (...args: any[]) => {
138
for (let i = 0; i < boundArgs.length; ++i) {
14-
table.insert(argArray, i + 1, boundArgs[i]);
9+
table.insert(args, i + 1, boundArgs[i]);
1510
}
16-
return fn(thisArg, (unpack || table.unpack)(argArray));
11+
return fn(thisArg, (unpack || table.unpack)(args));
1712
};
1813
}

src/lualib/FunctionCall.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
declare function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
2-
3-
declare namespace table {
4-
export function unpack<T>(this: void, list: T[], i?: number, j?: number): T[];
5-
}
6-
7-
type CallFn = (this: void, ...argArray: any[]) => any;
8-
9-
function __TS__FunctionCall(this: void, fn: CallFn, thisArg: any, ...args: any[]): any {
1+
function __TS__FunctionCall(
2+
this: void,
3+
fn: (this: void, ...args: any[]) => any,
4+
thisArg: any,
5+
...args: any[]
6+
): any {
107
return fn(thisArg, (unpack || table.unpack)(args));
118
}

0 commit comments

Comments
 (0)