Skip to content

Type system for actions #128

@girvel

Description

@girvel

There's an abstract "class" action.base, that provides methods :act and :is_available and may use :_act and :_is_available. Currently, actions are implemented through Table.extend with action.base as a second argument. This has a few downsides:

  1. Generally, getmetatable(x) does type checking for x. Actions do not follow that convention.
  2. Using Table.extend is not fully compatible with LuaLS; :is_available and :act have parameter types, underscore methods do not.
  3. Action definitions break type definition convention (local methods = {} stuff)

Proposal:

  1. Use metatable inheritance:
local methods = setmetatable({}, {__index = parent_mt.__index})

-- or maybe
local methods = Table.inherit(parent.mt)
  1. action.base -> action.mt
  2. Maybe Table.inherits_mt(x, mt) -> boolean to check inheritance

That's kind of OOP-ish, but otherwise seems to do the job.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions