Coding & Naming conventions

Naming conventions

Class and OOP Conventions

IMPORTANT: Lilush follows a specific pattern for defining classes and object-oriented code. This convention must be used consistently throughout the codebase.

Method Definition: Always use explicit function assignment, never the colon syntax for definitions:

local get_name = function(self)
    return self.__name
end

local set_name = function(self, name)
    self.__name = name
end

Method calls: Method calls use the regular Lua syntactic sugar: my_obj:set_name("Jimmy")

Constructor Pattern: Use a simple new function that returns a table with methods assigned directly (no metatables by default):

local new = function(config, opts)

    local instance = {
        cfg = config,
        -- private fields
        __state = {
            reloads = 0
        },
        __window = {
            size = opts.window_size,
        },    
        __value = opts.value,
        __cache = {},

        -- Methods assigned directly
        get_value = get_value,
        set_value = set_value,
        process = process,
    }

    return instance
end

-- Module export
return {
    new = new,
}

Key Points:

  1. No ClassName = {} with __index metatables

  2. No function ClassName:method() syntax for definitions

  3. Methods are defined as local functions, then assigned in the constructor

  4. Helper functions that don't need self remain standalone local functions

  5. Module exports only what's needed (OOP modules typically export new; library modules export a table of functions)

Metatables Policy:

Documentation comments

Function and module documentation follows the LIMAN doc comment format. See LIMAN.md for the ---!, ---@, and --[===[ conventions.

Module namespacing

C modules use std.core, term.core, crypto.core naming to separate from Lua APIs.