Skip to content

Commit 88ce1b1

Browse files
committed
declare LuaThread and LuaUserdata as interfaces
1 parent f8155f7 commit 88ce1b1

4 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎core/5.0/global.d.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
/** @noSelfInFile */
44

5-
type LuaThread = { readonly __internal__: unique symbol };
6-
type LuaUserdata = { readonly __internal__: unique symbol };
5+
interface LuaThread {
6+
readonly __internal__: unique symbol;
7+
}
8+
interface LuaUserdata {
9+
readonly __internal__: unique symbol;
10+
}
711

812
/**
913
* A global variable (not a function) that holds a string containing the running

‎core/global.d.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
/** @noSelfInFile */
66

7-
type LuaThread = { readonly __internal__: unique symbol };
8-
type LuaUserdata = { readonly __internal__: unique symbol };
7+
interface LuaThread {
8+
readonly __internal__: unique symbol;
9+
}
10+
interface LuaUserdata {
11+
readonly __internal__: unique symbol;
12+
}
913

1014
/**
1115
* A global variable (not a function) that holds a string containing the running

‎test/__snapshots__/global.spec.ts.snap‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Lua version 5.1 / global LuaThread and LuaUserdata can be extended 1`] = `
4+
"thread = coroutine.create(function()
5+
end)
6+
threadTag = thread.tag
7+
userdataTag = userdata.tag"
8+
`;
9+
310
exports[`Lua version 5.1 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;
411

512
exports[`Lua version 5.1 / global assert 2`] = `"assert(false, \\"assert message\\")"`;
@@ -104,6 +111,13 @@ exports[`Lua version 5.1 / global tostring 1`] = `"str = tostring(213.4)"`;
104111

105112
exports[`Lua version 5.1 / global type 1`] = `"t = type(213.4)"`;
106113

114+
exports[`Lua version 5.2 / global LuaThread and LuaUserdata can be extended 1`] = `
115+
"thread = coroutine.create(function()
116+
end)
117+
threadTag = thread.tag
118+
userdataTag = userdata.tag"
119+
`;
120+
107121
exports[`Lua version 5.2 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;
108122

109123
exports[`Lua version 5.2 / global assert 2`] = `"assert(false, \\"assert message\\")"`;
@@ -208,6 +222,13 @@ exports[`Lua version 5.2 / global tostring 1`] = `"str = tostring(213.4)"`;
208222

209223
exports[`Lua version 5.2 / global type 1`] = `"t = type(213.4)"`;
210224

225+
exports[`Lua version 5.3 / global LuaThread and LuaUserdata can be extended 1`] = `
226+
"thread = coroutine.create(function()
227+
end)
228+
threadTag = thread.tag
229+
userdataTag = userdata.tag"
230+
`;
231+
211232
exports[`Lua version 5.3 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;
212233

213234
exports[`Lua version 5.3 / global assert 2`] = `"assert(false, \\"assert message\\")"`;
@@ -312,6 +333,13 @@ exports[`Lua version 5.3 / global tostring 1`] = `"str = tostring(213.4)"`;
312333

313334
exports[`Lua version 5.3 / global type 1`] = `"t = type(213.4)"`;
314335

336+
exports[`Lua version 5.4 / global LuaThread and LuaUserdata can be extended 1`] = `
337+
"thread = coroutine.create(function()
338+
end)
339+
threadTag = thread.tag
340+
userdataTag = userdata.tag"
341+
`;
342+
315343
exports[`Lua version 5.4 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;
316344

317345
exports[`Lua version 5.4 / global assert 2`] = `"assert(false, \\"assert message\\")"`;
@@ -416,6 +444,13 @@ exports[`Lua version 5.4 / global tostring 1`] = `"str = tostring(213.4)"`;
416444

417445
exports[`Lua version 5.4 / global type 1`] = `"t = type(213.4)"`;
418446

447+
exports[`Lua version JIT / global LuaThread and LuaUserdata can be extended 1`] = `
448+
"thread = coroutine.create(function()
449+
end)
450+
threadTag = thread.tag
451+
userdataTag = userdata.tag"
452+
`;
453+
419454
exports[`Lua version JIT / global assert 1`] = `"assert({bla = \\"not false\\"})"`;
420455

421456
exports[`Lua version JIT / global assert 2`] = `"assert(false, \\"assert message\\")"`;

‎test/global.spec.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,20 @@ describeForEachLuaTarget('global', (target) => {
285285

286286
expect(lua).toMatchSnapshot();
287287
});
288+
289+
test('LuaThread and LuaUserdata can be extended', () => {
290+
const lua = tstl(
291+
target,
292+
`
293+
interface LuaThread { readonly tag?: 'thread' }
294+
interface LuaUserdata { readonly tag?: 'userdata' }
295+
declare const userdata: LuaUserdata;
296+
const thread = coroutine.create(() => {});
297+
const threadTag: 'thread' | undefined = thread.tag;
298+
const userdataTag: 'userdata' | undefined = userdata.tag;
299+
`
300+
);
301+
302+
expect(lua).toMatchSnapshot();
303+
});
288304
});

0 commit comments

Comments
 (0)