🌴 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 -f kailua

(-f will cause the existing installation to be upgraded.)

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. The configuration format is described in the later section.

Visual Studio Code

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). If you are not on Windows, you should also install the standalone checker as above.

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 { "start_path": "",

"preload": {
    // This indicates that we are using Lua 5.1 and all built-in libraries of it.
    "open": ["lua51"],
},

} ```

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!')

If you are using the configuration file, the first code can be made much simpler:

lua 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:

Configuration Format

You can configure the exact behavior of Kailua with kailua.json. It is a JSON with comments (//) and stray comma allowed for convenience:

```json5 { // This indicates where to start. This is the only mandatory field in the file. // // This can be a single string or an array of strings, and in the latter case // multiple paths are separately (but possibly parallelly) checked against. // Checking sessions do not affect others, but reports are merged. "startpath": ["entrypoint.lua", "lib/myawesome_lib.lua"],

// These are values for `package.path` and `package.cpath` variables, respectively.
// Refer to the Lua manual for the exact format.
//
// If they are not explicitly set, they are inferred from any assignments to
// `package.path` and `package.cpath` variables. This can be handy for scripts,
// but will be cumbersome for most other cases.
//
// It should be also noted that any path in `package_cpath` won't be directly
// read by Kailua; only `.kailua` files associated to them will be read.
"package_path": "?.lua;contrib/?.lua",
"package_cpath": "native/?",

// The preloading options to populate the environment before checking.
// They are executed in the following order, and in each array, in given order.
"preload": {
    // A list of `--# open` arguments.
    "open": ["lua51"],
    // A list of `require()` arguments. Affected by `package_*` options.
    "require": ["depA", "depB.core"],
},

} ```

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.