Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/5.0/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

/** @noSelfInFile */

type LuaThread = { readonly __internal__: unique symbol };
type LuaUserdata = { readonly __internal__: unique symbol };
interface LuaThread {
readonly __internal__: unique symbol;
}
interface LuaUserdata {
readonly __internal__: unique symbol;
}

/**
* A global variable (not a function) that holds a string containing the running
Expand Down
8 changes: 6 additions & 2 deletions core/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

/** @noSelfInFile */

type LuaThread = { readonly __internal__: unique symbol };
type LuaUserdata = { readonly __internal__: unique symbol };
interface LuaThread {
readonly __internal__: unique symbol;
}
interface LuaUserdata {
readonly __internal__: unique symbol;
}

/**
* A global variable (not a function) that holds a string containing the running
Expand Down
35 changes: 35 additions & 0 deletions test/__snapshots__/global.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Lua version 5.1 / global LuaThread and LuaUserdata can be extended 1`] = `
"thread = coroutine.create(function()
end)
threadTag = thread.tag
userdataTag = userdata.tag"
`;

exports[`Lua version 5.1 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;

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

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

exports[`Lua version 5.2 / global LuaThread and LuaUserdata can be extended 1`] = `
"thread = coroutine.create(function()
end)
threadTag = thread.tag
userdataTag = userdata.tag"
`;

exports[`Lua version 5.2 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;

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

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

exports[`Lua version 5.3 / global LuaThread and LuaUserdata can be extended 1`] = `
"thread = coroutine.create(function()
end)
threadTag = thread.tag
userdataTag = userdata.tag"
`;

exports[`Lua version 5.3 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;

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

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

exports[`Lua version 5.4 / global LuaThread and LuaUserdata can be extended 1`] = `
"thread = coroutine.create(function()
end)
threadTag = thread.tag
userdataTag = userdata.tag"
`;

exports[`Lua version 5.4 / global assert 1`] = `"assert({bla = \\"not false\\"})"`;

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

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

exports[`Lua version JIT / global LuaThread and LuaUserdata can be extended 1`] = `
"thread = coroutine.create(function()
end)
threadTag = thread.tag
userdataTag = userdata.tag"
`;

exports[`Lua version JIT / global assert 1`] = `"assert({bla = \\"not false\\"})"`;

exports[`Lua version JIT / global assert 2`] = `"assert(false, \\"assert message\\")"`;
Expand Down
16 changes: 16 additions & 0 deletions test/global.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,20 @@ describeForEachLuaTarget('global', (target) => {

expect(lua).toMatchSnapshot();
});

test('LuaThread and LuaUserdata can be extended', () => {
const lua = tstl(
target,
`
interface LuaThread { readonly tag?: 'thread' }
interface LuaUserdata { readonly tag?: 'userdata' }
declare const userdata: LuaUserdata;
const thread = coroutine.create(() => {});
const threadTag: 'thread' | undefined = thread.tag;
const userdataTag: 'userdata' | undefined = userdata.tag;
`
);

expect(lua).toMatchSnapshot();
});
});