🌴 Kailua

한국어

Kailua is an experimental type checker and integrated development environment (IDE) for the [Lua] programming language (currently only Lua 5.1 is supported).

THIS IS VERY EXPERIMENTAL PROJECT AND NO WARRANTY OR SUPPORT IS PROVIDED!

Installation and Usage

Kailua can be used as a standalone checker or an IDE plugin.

Standalone Checker

To install a standalone checker, [install Rust] first (1.15 or later required), then type the following:

cargo install kailua

You can run kailua check <path to the entry point> now.

You can also run kailua check <path to the directory>, if you have kailua.json or .vscode/kailua.json in that directory. See the following section on the configuration format.

Visual Studio Code

Caution: Currently the extension only works in Windows due to the packaging issue.

Kailua can be used as an IDE support for Visual Studio Code. Install Kailua by typing ext install kailua from the Quick Launch (Ctrl-P).

You will see a warning that the configuration file is missing when you open a folder containing Lua codes. You need it for real-time checking.

You can either create .vscode/kailua.json by hand, or search "Kailua" from the Command Palette (Ctrl-Shift-P) to edit one.

The following content is required for .vscode/kailua.json, in case you are editing it by hand:

```json5 { // Unlike a normal JSON, a comment or a stray comma is allowed. "start_path": "",

// You can also put the following:
//
//"package_path": "<the value of `package.path`, determined from assignments if missing>",
//"package_cpath": "<the value of `package.cpath`, determined from assignments if missing>",

} ```

You need to reload the current window (Ctrl-R or Cmd-R) to apply the configuration.

Your First Kailua Code

Once you've set the entry point, you can write your first Kailua code:

lua --# open lua51 print('Hello, world!')

Play a bit with this code to see which errors Kailua can detect.

Supported IDE Functions

Kailua the Language

Special Comments

Kailua is a subset of valid Lua code---you don't need any transpilation or compilation. The additional annotations are described in special comments:

The equal kind of special comments can span multiple lines.

lua --# type Date = { --# hour: integer; --# min: integer; --# sec: integer; --# }

Types

The following basic types are recognized:

The Kailua types are by default not checked for nil. That is, you can assign nil to integer but you can also add two integers; the valid Kailua code can still result in a runtime error therefore. This restriction was required for making a practical type checker without changing the source programming language.

You can opt in two other nil-handling modes if you need to make it explicit. As they are (transitively) freely assignable, consider them more a machine-readable documentation.

Also, the table values are always T or T? (for the obvious reason).

Finally, types for the names and table values can optionally have a const prefix. You cannot modify the innard of const types: map<integer, const vector<string>>. You can still assign to them (otherwise this type won't be useful at all).

Avoiding the type checker

As annotating everything is not practical, Kailua supports two ways to avoid the type checking with more localized guarantees:

See Also

The internal documentation is available in a different file.

License

Kailua is dual-licensed under the MIT license and Apache license 2.0 at your option. By contributing to Kailua you agree that your contributions will be licensed under these two licenses.