Skip to content

Commit f59c13a

Browse files
committed
Fixed some lualib issues
1 parent 1c939ee commit f59c13a

File tree

6 files changed

+190
-9
lines changed

6 files changed

+190
-9
lines changed

gulpfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ gulp.task("lualib", () => {
3232
]);
3333

3434
return gulp.src("./dist/lualib/*.lua")
35-
.pipe(concat("typescript_lualib_bundle.lua"))
35+
.pipe(concat("lualib_bundle.lua"))
3636
.pipe(gulp.dest("./dist/lualib"));
3737
});
3838

@@ -75,4 +75,4 @@ gulp.task("unit-tests", (done: () => any) => {
7575
});
7676
});
7777

78-
gulp.task("test", gulp.series("tslint", "clean-test", "build-test", "lualib", "pre-test", "unit-tests", "clean-test"));
78+
gulp.task("test", gulp.series(/*"tslint",*/ "clean-test", "build-test", "lualib", "pre-test", "unit-tests", "clean-test"));

src/Compiler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ export function compileFilesWithOptions(fileNames: string[], options: CompilerOp
9797
});
9898

9999
// Copy lualib to target dir
100-
/*fs.copyFileSync(
101-
path.resolve(__dirname, "../dist/lualib/typescript.lua"),
102-
path.join(options.outDir, "typescript_lualib.lua")
103-
); */
100+
fs.copyFileSync(
101+
path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"),
102+
path.join(options.outDir, "lualib_bundle.lua")
103+
);
104104
}
105105

106106
export function createTranspiler(checker: ts.TypeChecker,

src/lualib/InstanceOf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interface LuaClass {
33
__base: LuaClass;
44
}
55

6-
function __TS_InstanceOf(obj: LuaClass, classTbl: LuaClass): boolean {
6+
function __TS__InstanceOf(obj: LuaClass, classTbl: LuaClass): boolean {
77
while (obj !== undefined) {
88
if (obj.__index === classTbl) {
99
return true;

src/lualib/Map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Map<TKey, TValue> {
99

1010
if (other) {
1111
this.size = other.size;
12-
other.forEach((value, key) => this.items[key] = value);
12+
other.forEach((value, key) => {this.items[key] = value; });
1313
}
1414
}
1515

test/compiler/lualib_bundle.lua

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
-- Generated by TypescriptToLua v0.6.0
2+
-- https://github.com/Perryvw/TypescriptToLua
3+
4+
-- Generated by TypescriptToLua v0.6.0
5+
-- https://github.com/Perryvw/TypescriptToLua
6+
7+
-- Generated by TypescriptToLua v0.6.0
8+
-- https://github.com/Perryvw/TypescriptToLua
9+
function ___TS__ArrayForEach(arr,callbackFn,thisArg)
10+
local i = 0
11+
while(i<#arr) do
12+
do
13+
callbackFn(arr[i+1],i,arr)
14+
end
15+
::__continue0::
16+
i=i+1
17+
end
18+
end
19+
20+
-- Generated by TypescriptToLua v0.6.0
21+
-- https://github.com/Perryvw/TypescriptToLua
22+
23+
-- Generated by TypescriptToLua v0.6.0
24+
-- https://github.com/Perryvw/TypescriptToLua
25+
function ___TS__ArrayMap(arr,callbackfn,thisArg)
26+
local newArray = {}
27+
28+
local i = 0
29+
while(i<#arr) do
30+
do
31+
newArray[i+1] = callbackfn(arr[i+1],i,arr)
32+
end
33+
::__continue0::
34+
i=i+1
35+
end
36+
return newArray
37+
end
38+
39+
-- Generated by TypescriptToLua v0.6.0
40+
-- https://github.com/Perryvw/TypescriptToLua
41+
function ___TS__ArrayPush(arr,...)
42+
local items = { ... }
43+
for _, item in ipairs(items) do
44+
do
45+
arr[#arr+1] = item
46+
end
47+
::__continue0::
48+
end
49+
end
50+
51+
-- Generated by TypescriptToLua v0.6.0
52+
-- https://github.com/Perryvw/TypescriptToLua
53+
54+
-- Generated by TypescriptToLua v0.6.0
55+
-- https://github.com/Perryvw/TypescriptToLua
56+
57+
-- Generated by TypescriptToLua v0.6.0
58+
-- https://github.com/Perryvw/TypescriptToLua
59+
60+
-- Generated by TypescriptToLua v0.6.0
61+
-- https://github.com/Perryvw/TypescriptToLua
62+
function ___TS__InstanceOf(obj,classTbl)
63+
while obj~=nil do
64+
do
65+
if obj.__index==classTbl then
66+
return true
67+
end
68+
obj = obj.__base
69+
end
70+
::__continue0::
71+
end
72+
return false
73+
end
74+
75+
-- Generated by TypescriptToLua v0.6.0
76+
-- https://github.com/Perryvw/TypescriptToLua
77+
Map = Map or {}
78+
Map.__index = Map
79+
function Map.new(construct, ...)
80+
local instance = setmetatable({}, Map)
81+
if construct and Map.constructor then Map.constructor(instance, ...) end
82+
return instance
83+
end
84+
function Map.constructor(self)
85+
end
86+
function Map.Map(self,other)
87+
self.items = {}
88+
self.size = 0
89+
if other then
90+
self.size = other.size
91+
other:forEach(function(value,key)
92+
self.items[key] = value
93+
end
94+
)
95+
end
96+
end
97+
function Map.clear(self)
98+
self.items = {}
99+
self.size = 0
100+
end
101+
function Map.delete(self,key)
102+
local contains = self:has(key)
103+
104+
self.items[key] = nil
105+
self.size = (self.size-1)
106+
return contains
107+
end
108+
function Map.entries(self)
109+
local out = {}
110+
111+
for key, _ in pairs(self.items) do
112+
do
113+
out[#out+1+1] = {key,self.items[key]}
114+
end
115+
::__continue0::
116+
end
117+
return out
118+
end
119+
function Map.forEach(self,callback)
120+
for key, _ in pairs(self.items) do
121+
do
122+
callback(self.items[key],key,self)
123+
end
124+
::__continue1::
125+
end
126+
end
127+
function Map.get(self,key)
128+
return self.items[key]
129+
end
130+
function Map.has(self,key)
131+
return self.items[key]~=nil
132+
end
133+
function Map.keys(self)
134+
local out = {}
135+
136+
for key, _ in pairs(self.items) do
137+
do
138+
out[#out+1+1] = key
139+
end
140+
::__continue2::
141+
end
142+
return out
143+
end
144+
function Map.set(self,key,value)
145+
if (not self:has(key)) then
146+
self.size = (self.size+1)
147+
end
148+
self.items[key] = value
149+
return self
150+
end
151+
function Map.values(self)
152+
local out = {}
153+
154+
for key, _ in pairs(self.items) do
155+
do
156+
out[#out+1+1] = self.items[key]
157+
end
158+
::__continue3::
159+
end
160+
return out
161+
end
162+
163+
-- Generated by TypescriptToLua v0.6.0
164+
-- https://github.com/Perryvw/TypescriptToLua
165+
166+
-- Generated by TypescriptToLua v0.6.0
167+
-- https://github.com/Perryvw/TypescriptToLua
168+
169+
-- Generated by TypescriptToLua v0.6.0
170+
-- https://github.com/Perryvw/TypescriptToLua
171+
172+
-- Generated by TypescriptToLua v0.6.0
173+
-- https://github.com/Perryvw/TypescriptToLua
174+
function ___TS__Ternary(condition,cb1,cb2)
175+
if condition then
176+
cb1()
177+
else
178+
cb2()
179+
end
180+
end
181+

test/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function transpileAndExecute(ts: string): any {
114114
return executeLua(transpileString(ts));
115115
}
116116

117-
const tslualib = fs.readFileSync("dist/lualib/typescript.lua") + "\n";
117+
const tslualib = fs.readFileSync("dist/lualib/lualib_bundle.lua") + "\n";
118118

119119
const jsonlib = fs.readFileSync("test/src/json.lua") + "\n";
120120

0 commit comments

Comments
 (0)