Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ deploy:
secure: zXFXK1GohutgqKXQ101uKcJKcf0wgCuVPFMY44Xl/JwXeLsA1CJ4aqUdoXh2ramcI+9wTVj7RR3N3/7W+2DeDCfUlj+gxw26pTV3EUnU2B1TXEz01Ar07WPHmhHJSS5tgyo9kPUqm/YBFkJuDtfx0Kp3sL6IRYDddvGv/2L1X8r3I14PxgppkU9T4FGINdClOEwfwelmxx3kjxpnTsUHZ+ztx7o+blteSf/r+pT1RDaIap80JaTy6vHwJKECRSvtpyTKEYeVmBIaA3yXqRhfMdlp8bU20t2DXoDGXWPk0GXRGXkVHE6yj64gPe/eOOesAxzv0v/vr5w4poemJ+SGwP3RSbrbVtiusD4FC6+hFBH7hiNUhxww5euvbAfNOTq2XyxtjcNmKB5/O675xGihK1gBgrsPdJ4enwkhQNrUuQBHm5wIKGiaH7t7q+T8W9JAnk3FGGuSZPg9b7AnFDQ3graxZK9mtOxi0GvE7DHinH6qErd4noGjS/KSy1fnDkCEkeplOQmvxb4w7wLMR5pePFc77NBXiR3RJDKh4QKskcvXPx58OWNffTkS2QwYPYhraNNKbUfGFBNEA4KPNmw1jYlDE/1BhOebmONpZQMP/CdcCWL+CKyTdi1/289Ak4B0iSZZN+Yx+AONzPlcvBVi+bXeXtqoIt2zMFKkr/0YFQg=
on:
tags: true
repo: Perryvw/TypescriptToLua
repo: TypeScriptToLua/TypeScriptToLua
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# TypeScriptToLua
<div align="center">
<img src="logo-hq.png?raw=true" alt="TypeScriptToLua" width="256" />
<h1>
TypeScriptToLua
<p></p>
<a href="https://travis-ci.org/TypeScriptToLua/TypeScriptToLua"><img alt="Build status" src="https://img.shields.io/travis/TypeScriptToLua/TypeScriptToLua.svg?style=for-the-badge" /></a>
<a href="https://ci.appveyor.com/project/Perryvw/typescripttolua-pa0ym"><img alt="Build status" src="https://img.shields.io/appveyor/ci/Perryvw/typescripttolua-pa0ym.svg?logo=appveyor&style=for-the-badge" /></a>
<a href="https://codecov.io/gh/TypeScriptToLua/typescripttolua"><img alt="Coverage" src="https://img.shields.io/codecov/c/gh/TypeScriptToLua/typescripttolua.svg?logo=codecov&style=for-the-badge" /></a>
<a href="https://discord.gg/BWAq58Y"><img alt="Chat with us!" src="https://img.shields.io/discord/515854149821267971.svg?style=for-the-badge&colorB=7581dc&logo=discord&logoColor=white"></a>
</h1>
</div>

A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!

Large projects written in lua can become hard to maintain and make it easy to make mistakes. Writing code in TypeScript instead improves maintainability, readability and robustness, with the added bonus of good IDE support. This project is useful in any environment where Lua code is accepted, with the powerful option of simply declaring any existing API using TypeScript declaration files.

[![Build Status](https://travis-ci.org/Perryvw/TypescriptToLua.svg?branch=master)](https://travis-ci.org/Perryvw/TypescriptToLua)
[![Build status](https://ci.appveyor.com/api/projects/status/github/perryvw/typescripttolua?branch=master&svg=true)](https://ci.appveyor.com/project/Perryvw/typescripttolua)
[![Coverage](https://codecov.io/gh/perryvw/typescripttolua/branch/master/graph/badge.svg)](https://codecov.io/gh/perryvw/typescripttolua)

You can chat with us on [Discord: ![Discord](https://img.shields.io/discord/515854149821267971.svg)](https://discord.gg/BWAq58Y)

## Documentation
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/Perryvw/TypescriptToLua/wiki).
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/TypeScriptToLua/TypescriptToLua/wiki).

Changelog can be found in [CHANGELOG.md](https://github.com/Perryvw/TypescriptToLua/blob/master/CHANGELOG.md)
Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CHANGELOG.md)

## Usage Guide

Expand Down Expand Up @@ -46,7 +51,7 @@ Changelog can be found in [CHANGELOG.md](https://github.com/Perryvw/TypescriptTo
```

## Contributing
All contributions are welcome, but please read our [contribution guidelines](https://github.com/Perryvw/TypescriptToLua/blob/master/CONTRIBUTING.md)!
All contributions are welcome, but please read our [contribution guidelines](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CONTRIBUTING.md)!

## Declarations
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of Lua interface declarations can be found here:
Expand Down
Binary file added logo-hq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 23 additions & 6 deletions src/CommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type ParseResult<T> =
{ isValid: true; result: T }
| { isValid: false, errorMessage: string};

type ArgumentParseResult<T> =
{ isValid: true; result: T; increment?: number }
| { isValid: false, errorMessage: string };

interface ParsedCommandLine extends ts.ParsedCommandLine {
options: CompilerOptions;
}
Expand Down Expand Up @@ -190,10 +194,11 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
const argumentName = args[i].substr(2);
const option = optionDeclarations[argumentName];
if (option) {
const argumentResult = getArgumentValue(argumentName, args[i + 1]);
i++; // Skip the value from being considered as argument name
const argumentResult = getArgumentValue(argumentName, i, args);
if (argumentResult.isValid === true) {
result[argumentName] = argumentResult.result;
// Skip value from being considered as option
i += argumentResult.increment !== undefined ? argumentResult.increment : 1;
} else {
return { isValid: false, errorMessage: argumentResult.errorMessage };
}
Expand All @@ -209,10 +214,11 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
}

if (argumentName) {
const argumentResult = getArgumentValue(argumentName, args[i + 1]);
i++; // Skip the value from being considered as argument name
const argumentResult = getArgumentValue(argumentName, i, args);
if (argumentResult.isValid === true) {
result[argumentName] = argumentResult.result;
// Skip value from being considered as option
i += argumentResult.increment !== undefined ? argumentResult.increment : 1;
} else {
return { isValid: false, errorMessage: argumentResult.errorMessage };
}
Expand All @@ -232,13 +238,24 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
return { isValid: true, result: commandLine };
}

function getArgumentValue(argumentName: string, argument: string): ParseResult<string | boolean>
function getArgumentValue(
argumentName: string,
argumentIndex: number,
args: string[]
): ArgumentParseResult<string | boolean>
{
const option = optionDeclarations[argumentName];
const argument = args[argumentIndex + 1];

if (option.type === "boolean" && (argument === undefined || argument.startsWith("-"))) {
// Set boolean arguments without supplied value to true
return { isValid: true, result: true, increment: 0 };
}

if (argument === undefined) {
return { isValid: false, errorMessage: `Missing value for parameter ${argumentName}`};
}

const option = optionDeclarations[argumentName];
const value = readValue(argument, option.type, argumentName);

if (option.choices) {
Expand Down
Loading