用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill agentic-lua-class命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | agentic-lua-class |
| description | > Use when this capability is needed. |
Basic class structure:
--- @class Animal
local Animal = {}
Animal.__index = Animal
function Animal:new()
self = setmetatable({}, self)
return self
end
function Animal:move()
print("Animal moves")
end
Key points:
__index to self for inheritancesetmetatable to create instancesMethod definition syntax:
function Class:method() - Instance method, receives self implicitly
instance:method() or instance.method(instance)function Class.method() - Module function, static, does NOT receive self
Class.method() or instance.method() (both work, but no
self)Class setup (module-level):
local Parent = {}
Parent.__index = Parent
--- @class Child : Parent
local Child = setmetatable({}, { __index = Parent })
Child.__index = Child
Constructor with parent initialization:
function Parent:new(name)
local instance = {
name = name,
parent_state = {}
}
return setmetatable(instance, self)
end
function Child:new(name, extra)
-- Call parent constructor with Parent class
local instance = Parent.new(Parent, name)
-- Add child-specific state
instance.child_state = extra
-- Re-metatable to child class for proper inheritance chain
return setmetatable(instance, Child)
end
Critical rules:
Parent.new(Parent, ...) not
Parent.new(self, ...)instance → Child → ParentCalling parent methods:
function Child:move()
Parent.move(self) -- Explicit parent method call
print("Child-specific movement")
end
Minimize class properties - Only include properties that:
Use visibility prefixes for encapsulation - Control what external code can access:
Visibility levels (configured in .luarc.json):
_*: Private - Hidden from external consumers (applies to class
methods/fields ONLY)__*: Protected - Visible to subclassesIMPORTANT: Module-level local functions and variables do NOT need _
prefix:
local function helper() - correct (already private by local scope)local function _helper() - incorrect (redundant _ prefix)local config = {} - correctlocal _config = {} - incorrect (redundant _ prefix)function MyClass:_private_method() - correct (class method needs _)@field _private_field - correct (class field needs _)-- ❌ Bad: Unnecessary public exposure of `counter` property, not used externally
--- @class MyClass
--- @field counter number
local MyClass = {}
MyClass.__index = MyClass
function MyClass:new()
return setmetatable({ counter = 0 }, self)
end
-- ✅ Good: Proper visibility control
--- @class MyClass
local MyClass = {}
MyClass. = MyClass
({
_counter =
}, )
._counter = ._counter +
(val)
:__protected_method()
Space after --- for descriptions and annotations. Do NOT write param/return
descriptions unless requested. Group related annotations together.
@return {type} return_name description (type first, then name).
@return boolean success Whether the operation succeeded@return boolean Whether the operation succeeded (missing name)@return success boolean (wrong order)Format depends on annotation type. See LuaLS issue #2385 for the underlying validator limitation.
@param and fun() - MUST use type|nil:
@param winid number|nil@param callback fun(result: table|nil)@param winid? number (LuaLS does not validate optional syntax)fun(result?: table) (optional syntax ignored)@field - Use variable? type:
@field _state? string@field diff? { all?: boolean } (inline tables also use ?)@field _state string|nil (use ? here instead)@field _state string? (? goes after variable name, not type)For a partial variant of an existing class, use @class (partial) extending the
source type instead of re-declaring every field as optional.
@class (partial) MyOptsOverride: MyOpts@field field? type for every field from MyOpts@return, @type, @alias - Use explicit type|nil:
@return string|nil result, @type table<string, number|nil>,
@alias MyType string|nil? on the type (e.g. string?, number?)LuaLS cannot infer types from inline returns of complex types. Use a typed intermediate variable:
-- Bad: LuaLS cannot infer the return type
function M.create_block(lines)
return {
start_line = 1,
end_line = #lines,
content = lines,
}
end
-- Good: Type annotation enables proper type checking
--- @return MyModule.Block block
function M.create_block(lines)
--- @type MyModule.Block
local block = {
start_line = 1,
end_line = #lines,
content = lines,
}
return block
end
Use arr[#arr + 1] = value, not table.insert(arr, value), when arr has a
LuaCATS element type (string[], agentic.acp.Content[], a typed field, etc.).
table.insert's second arg is variadic any, so LuaLS skips
assign-type-mismatch (an Error in .luarc.json). The indexed-assignment form
is type-checked against the element type and catches wrong-type appends and
stale @return / @type annotations.
lines[#lines + 1] = value (flags a non-string pushed to string[])table.insert(lines, value) (push silently accepted)table.insert stays fine for positional inserts (table.insert(t, i, v)) and
untyped scratch tables where no element type is declared.
Source: carlos-algms/agentic.nvim — distributed by TomeVault.
Note: The @private annotation is NOT necessary for private class methods
_ prefix automatically@protected for protected methods (__*, luals limitation)Document intent with LuaCATS - Use visibility annotations:
--- @class MyClass
--- @field public_field string Public API
--- @field __protected_field table For subclasses
--- @field _private_field number Internal only
Regular cleanup - When adding new code, review class definitions and remove: