ImoLua Design

Created: 31-03-2026. Updated: 06-04-2026.

Most of the rules correspond to the tests.

Contents

  1. Interface
  2. Class

Interface

interface Arith
    add: (Int, Int) -> Int
    sub: (Int, Int) -> Int
end

Rules

Interface name must be capitalized

For consistency.

Interface can be empty

Interface is nominally typed.

Interface is erased

Similar to Typescript.


Class

class User
    data
        id: Int
        name: Str
    end
    new(id: Int, name: Str) -> Self
        return ^Self {id = id, name = name}
    end
end

Rules

Class name must be capitalized

For consistency.

This is similar to Ruby.

Class must have data section

This is the fields. For easy parsing. Might change later.

data section must be directly after class name

This is obvious.

data section must contain at least one field

Empty class is mostly for utility. In ImoLua, to make utility class you can use Lone object (later).

No special separator (like comma or semicolon) between fields in data section

ImoLua can parse it without ambiguity.

Class must have new constructor

Javascript's constructor is too long to type. There is no implicit constructor.

All fields and methods are public

Might change later.

Inside a class, you must refer to it as Self instead of the class name

There is only one way to do thing.

To instatiate a class C, call it and pass the args of new constructor

For above example:

let a = User(1, "Alex")

Don't instatiate using new constructor

new is not callable.

Instance method is called with implicit self argument

Follows Lua.

You cannot access instance method without calling it

Class is immutable. You cannot assign instance method to variable because self will not bound.

Call instance method with :

To differentatiate it with field/map access.

a:method(args)

Don't call instance method with .

a.method(args)  -- Wrong.

Access instance field with .

let id = a.id

Class cannot be reopened

Not like Ruby and JS.


End.