Skip to content

Commit f2a94f6

Browse files
committed
Merge branch 'pr/1'
2 parents ce0b8a7 + a406bbb commit f2a94f6

19 files changed

Lines changed: 51 additions & 6011 deletions

File tree

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "typescript-to-lua",
3-
"version": "1.27.0",
4-
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
5-
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
2+
"name": "@jackmacwindows/typescript-to-lua",
3+
"version": "1.22.0",
4+
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua! (With ComputerCraft support)",
5+
"repository": "https://github.com/MCJack123/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",
77
"bugs": {
88
"url": "https://github.com/TypeScriptToLua/TypeScriptToLua/issues"
@@ -64,7 +64,7 @@
6464
"javascript-stringify": "^2.0.1",
6565
"jest": "^29.5.0",
6666
"jest-circus": "^29.5.0",
67-
"lua-types": "^2.13.0",
67+
"@jackmacwindows/lua-types": "^2.13.0",
6868
"lua-wasm-bindings": "^0.3.1",
6969
"prettier": "^2.8.8",
7070
"ts-jest": "^29.1.0",

src/CompilerOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface TypeScriptToLuaOptions {
4040
tstlVerbose?: boolean;
4141
lua51AllowTryCatchInAsyncAwait?: boolean;
4242
measurePerformance?: boolean;
43+
luaLibName?: string;
4344
}
4445

4546
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> &
@@ -62,6 +63,8 @@ export enum LuaTarget {
6263
Lua53 = "5.3",
6364
Lua54 = "5.4",
6465
LuaJIT = "JIT",
66+
Cobalt = "CC",
67+
Cobalt52 = "CC-5.2"
6568
}
6669

6770
export enum BuildMode {

src/LuaLib.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ export function loadInlineLualibFeatures(
229229
export function loadImportedLualibFeatures(
230230
features: Iterable<LuaLibFeature>,
231231
luaTarget: LuaTarget,
232-
emitHost: EmitHost
232+
emitHost: EmitHost,
233+
luaLibName: string
233234
): lua.Statement[] {
234235
const luaLibModuleInfo = getLuaLibModulesInfo(luaTarget, emitHost);
235236

@@ -239,7 +240,7 @@ export function loadImportedLualibFeatures(
239240
}
240241

241242
const requireCall = lua.createCallExpression(lua.createIdentifier("require"), [
242-
lua.createStringLiteral("lualib_bundle"),
243+
lua.createStringLiteral(luaLibName),
243244
]);
244245

245246
const luaLibId = lua.createIdentifier("____lualib");

src/LuaPrinter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ export class LuaPrinter {
235235

236236
const luaTarget = this.options.luaTarget ?? LuaTarget.Universal;
237237
const luaLibImport = this.options.luaLibImport ?? LuaLibImportKind.Require;
238+
const luaLibName = this.options.luaLibName ?? "lualib_bundle";
238239
if (
239240
(luaLibImport === LuaLibImportKind.Require || luaLibImport === LuaLibImportKind.RequireMinimal) &&
240241
file.luaLibFeatures.size > 0
241242
) {
242243
// Import lualib features
243244
sourceChunks = this.printStatementArray(
244-
loadImportedLualibFeatures(file.luaLibFeatures, luaTarget, this.emitHost)
245+
loadImportedLualibFeatures(file.luaLibFeatures, luaTarget, this.emitHost, luaLibName)
245246
);
246247
} else if (luaLibImport === LuaLibImportKind.Inline && file.luaLibFeatures.size > 0) {
247248
// Inline lualib features

src/cli/parse.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export const optionDeclarations: CommandLineOption[] = [
5151
type: "enum",
5252
choices: Object.values(LuaLibImportKind),
5353
},
54+
{
55+
name: "luaLibName",
56+
description: "The name of the file to store Lua library features in.",
57+
type: "string",
58+
},
5459
{
5560
name: "luaTarget",
5661
aliases: ["lt"],

src/lualib-build/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LuaLibPlugin implements tstl.Plugin {
7070
let lualibBundle = orderedFeatures.map(f => exportedLualibFeatures.get(LuaLibFeature[f])).join("\n");
7171
const exports = allFeatures.flatMap(feature => luaLibModuleInfo[feature].exports);
7272
lualibBundle += getLualibBundleReturn(exports);
73-
result.push({ fileName: "lualib_bundle.lua", code: lualibBundle });
73+
result.push({ fileName: (options.luaLibName ?? "lualib_bundle") + ".lua", code: lualibBundle });
7474

7575
return diagnostics;
7676
}

src/lualib/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"outDir": "../../dist/lualib/universal",
44
"target": "esnext",
55
"lib": ["esnext"],
6-
"types": ["lua-types/5.4"],
6+
"types": ["@jackmacwindows/lua-types/cc"],
77
"skipLibCheck": true,
88
"rootDirs": [".", "universal"],
99

src/lualib/tsconfig.lua50.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"outDir": "../../dist/lualib/5.0",
44
"target": "esnext",
55
"lib": ["esnext"],
6-
"types": ["lua-types/5.0"],
6+
"types": ["@jackmacwindows/lua-types/5.0"],
77
"skipLibCheck": true,
88
"rootDirs": [".", "5.0"],
99

src/transformation/utils/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const unsupportedRightShiftOperator = createErrorDiagnosticFactory(
8585
"Right shift operator is not supported for target Lua 5.3. Use `>>>` instead."
8686
);
8787

88-
const getLuaTargetName = (version: LuaTarget) => (version === LuaTarget.LuaJIT ? "LuaJIT" : `Lua ${version}`);
88+
const getLuaTargetName = (version: LuaTarget) => (version === LuaTarget.LuaJIT ? "LuaJIT" : ((version === LuaTarget.Cobalt || version === LuaTarget.Cobalt52) ? "Cobalt" : `Lua ${version}`));
8989
export const unsupportedForTarget = createErrorDiagnosticFactory(
9090
(functionality: string, version: LuaTarget) =>
9191
`${functionality} is/are not supported for target ${getLuaTargetName(version)}.`

0 commit comments

Comments
 (0)