GithubHelp home page GithubHelp logo

lua-types's Introduction


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 tooling support (including ESLint, Prettier, Visual Studio Code and WebStorm). 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.

Getting Started

To install TypeScriptToLua add the typescript-to-lua npm package:

$ npm install -D typescript-to-lua

This package includes the tstl command line application, which can be used similarly to tsc:

$ npx tstl

For more information, check out Getting Started in our documentation.

lua-types's People

Contributors

ark120202 avatar dependabot[bot] avatar endel avatar glassbricks avatar hazzard993 avatar lolleko avatar martinjlowm avatar orta avatar perryvw avatar tomblind avatar yoryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lua-types's Issues

[Bug] Duplicate identifier 'LuaIterable'

Description

When I use [email protected] and [email protected] and execute tstl command the error appears:

node_modules/lua-types/core/global.d.ts:10:6 - error TS2300: Duplicate identifier 'LuaIterable'.

10 type LuaIterable<T> = Iterable<T> & { readonly __internal__: unique symbol };
        ~~~~~~~~~~~

  node_modules/typescript-to-lua/language-extensions/index.d.ts:73:14
    73 declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
                    ~~~~~~~~~~~
    'LuaIterable' was also declared here.

node_modules/typescript-to-lua/language-extensions/index.d.ts:73:14 - error TS2300: Duplicate identifier 'LuaIterable'.

73 declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
                ~~~~~~~~~~~

  node_modules/lua-types/core/global.d.ts:10:6
    10 type LuaIterable<T> = Iterable<T> & { readonly __internal__: unique symbol };
            ~~~~~~~~~~~
    'LuaIterable' was also declared here.

Environment
My package.json:
Link

My tsconfig.json:
Link

How to reproduce

git clone https://github.com/mtasa-typescript/resource-boilerplate types-issue-20
cd types-issue-20
git checkout 6fd89f

npm install

npm run build

The first block initializes configs
The second block installs all dependencies
And the last block triggers tstl command

Additional information
The same issue with /// <reference types="lua-types/5.1" />

NPM package doesn't include *.d.ts files

command: npm install -D types-lua

version: [email protected]

node_modules/types-lua:

C:.
│   LICENSE
│   package.json
│   README.md
│
└───types
        coroutine.d.ts
        debug.d.ts
        global.d.ts
        io.d.ts
        math.d.ts
        metatable.d.ts
        modules.d.ts
        os.d.ts
        string.d.ts
        table.d.ts
        utf8.d.ts

Missing files: 5.1.d.ts, 5.2.d.ts, 5.3.d.ts, 5.4.d.ts, jit.d.ts

Wrong signature of string.byte

Current signature:
function byte(s: string, i?: number, j?: number): number;

Should be instead:
/** @tuplereturn */ function byte(s: string, i?: number, j?: number): number[];
Since string.byte returns a tuple of numbers, one for each character in the specified range.

Indicate that pairs and ipairs give non-nullable values

pairs and ipairs never return nil values (undefined/null in typescript).
It would be useful if this was reflected in the signature of pairs/ipairs (using NonNullable<>), for lua-iterating types like Partial<...> or types with optional properties.

`repl` param of `string.gsub` seems to be incorrect

The types say: repl: string | Record<string, string> | ((...matches: string[]) => string),, whereas the above docstring says: "otherwise, if it is false or nil, then there is no replacement" - therefore, this should be an optional string, as it may be nil.

Furthermore, I believe a () capture group will return an index, so the matches aren't even necessarily a string[], but may be either number or string. gmatch etc might have similar issues.

You should maybe declare a match type which may be either a number or a string.

string.gsub incomplete

In string.gsub the third argument repl is typed as a string, but it should accept functions and tables as well (see reference). Perhaps something like string | {[key: string]: string} | (this:void, ...s:string[])=>string.

Reference:

  /**
   * Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see §6.4.1) have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred. The name gsub comes from Global SUBstitution.
   *
   * If repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %d, with d between 1 and 9, stands for the value of the d-th captured substring. The sequence %0 stands for the whole match. The sequence %% stands for a single %.
   *
   * If repl is a table, then the table is queried for every match, using the first capture as the key.
   *
   * If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order.
   *
   * In any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture.
   *
   * If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string).
   * @tupleReturn
   */
  function gsub(s: string, pattern: string, repl: string, n?: number): [string, number];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.