|
| 1 | +# Transpiling to Lua |
| 2 | + |
| 3 | +There are a whole host of languages out there that compile to Lua, allowing you |
| 4 | +to write your Usagi games in something other than vanilla Lua 5.5. Those |
| 5 | +languages might have other features or a style or syntax that you prefer. This |
| 6 | +recipe breaks down and shows some examples of how to go about this. |
| 7 | + |
| 8 | +Transpiling works by taking the source language and spitting out a `main.lua` |
| 9 | +file that `usagi` then uses. What's nice about this is that you can read through |
| 10 | +the Lua code that gets generated to help see what's really happening under the |
| 11 | +hood and debug potential issues. |
| 12 | + |
| 13 | +## MoonScript |
| 14 | + |
| 15 | +TODO: https://moonscript.org/ |
| 16 | + |
| 17 | +## Teal |
| 18 | + |
| 19 | +TODO: https://teal-language.org/ |
| 20 | + |
| 21 | +## TypeScript |
| 22 | + |
| 23 | +Using the [TypeScriptToLua](https://typescripttolua.github.io/) library, you can |
| 24 | +write your Usagi games in TypeScript, which is a typed version of JavaScript |
| 25 | +that's widely used in web development. You can use it with the `npm` package |
| 26 | +manager, possibly even with Bun or Deno too (but that hasn't been tested). |
| 27 | + |
| 28 | +Here's an example of a TypeScript Usagi game: |
| 29 | +[https://codeberg.org/brettchalupa/usagi/src/branch/main/examples/transpile/ts_to_lua](https://codeberg.org/brettchalupa/usagi/src/branch/main/examples/transpile/ts_to_lua) |
| 30 | + |
| 31 | +**Note:** the typedefs are currently very minimal and incomplete. Someone |
| 32 | +maintaining them as an external package would be a good community project. Or |
| 33 | +just write them by hand as you need them. |
| 34 | + |
| 35 | +Usagi relies a lot upon global functions, tables like `gfx` and `input`, and |
| 36 | +does not use objects or `self`. So when writing the TS, you'll need to set |
| 37 | +special parameters or add comments for the TypeScript compiler. Useful |
| 38 | +references: |
| 39 | + |
| 40 | +- [https://typescripttolua.github.io/docs/the-self-parameter](https://typescripttolua.github.io/docs/the-self-parameter) |
| 41 | +- [https://typescripttolua.github.io/docs/assigning-global-variables](https://typescripttolua.github.io/docs/assigning-global-variables) |
| 42 | + |
| 43 | +## YueScript |
| 44 | + |
| 45 | +TODO: https://yuescript.org/ |
| 46 | + |
| 47 | +## Browse the Examples |
| 48 | + |
| 49 | +The Usagi source code repository has a folder of transpiled examples: |
| 50 | +[https://codeberg.org/brettchalupa/usagi/src/branch/main/examples/transpile](https://codeberg.org/brettchalupa/usagi/src/branch/main/examples/transpile) |
0 commit comments