You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the best features of JS/TS ecosystem is the ability to create and reuse code with npm packages.
Currently it's impossible to create consumable libraries for Lua.
While working on my transpiler I have investigated it, so that's what I came up with:
Variant 1 - Transpilation done by application developer
Enforces some strict project structure for library authors
Requires reimpementing some TypeScript's project organization features, like project references
Makes transpiler API less flexible, since new TS programs would be created for each library internally
Would make transpilation a lot slower, unless some caching would be added
Variant 2 - Transpilation done by library developer
TypeScript and Babel are doing this
Allows to create projects that compile to both Lua and JS
Allows library author to use different/patched version of tstl and use custom plugins
Allows library author to customize build phase as they want (cli, gulp, custom scripts)
Allows to use libraries written manually with Lua and .d.ts files
Requires development of standard library as a separate package (maybe in a monorepo), so multiple libraries would use only one instance and version conflicts would be avoided with semver. TS is doing the same thing with tslib.
Complicates import path resolving process (but also makes it more flexible)
Not allows to configure optimizations globablly. For example if Add custom Array type to lualib #262 would be done as an option it won't be possible to use multiple libraries that are using different configurations
Libraries would be distributed like in TS - with a .lua and .d.ts files. To generate declarations tsc --emitDeclarationOnly could be used, but...
Some of semantics is lost on compilation phase. For example
exportclassA{getfoo(){return1;}}
exportdeclareclassA{readonlyfoo: number;}
So that would require customizing declaration generation to insert some metadata, similarity to what Kotlin is doing with generated java class files.
One of the best features of JS/TS ecosystem is the ability to create and reuse code with npm packages.
Currently it's impossible to create consumable libraries for Lua.
While working on my transpiler I have investigated it, so that's what I came up with:
Variant 1 - Transpilation done by application developer
Variant 2 - Transpilation done by library developer
tsc --emitDeclarationOnlycould be used, but...So that would require customizing declaration generation to insert some metadata, similarity to what Kotlin is doing with generated java class files.
I personally prefer second variant, but it comes with more issues to solve.