2.1 KiB
2.1 KiB
FlexLöve Agent Guidelines
Testing
- Run all tests:
lua testing/runAll.lua(coverage report inluacov.report.out) - Run single test:
lua testing/__tests__/<test_file>.lua - Test immediate mode: Call
FlexLove.setMode("immediate")insetUp(), thenFlexLove.beginFrame()/FlexLove.endFrame()to trigger layout
Code Style
- Modules: Use
local ModuleName = {}pattern, return table at end - Constructors:
ClassName.new(props)→ instance (always returns, never nil) - Instance methods:
instance:methodName()with colon syntax - Static methods:
ClassName.methodName()with dot syntax - Private fields: Prefix with
_(e.g.,self._internalState) - LuaDoc annotations: Use
---@param,---@return,---@class,---@fieldfor all public APIs - Error handling: Use
ErrorHandler.error(module, message)for critical errors,ErrorHandler.warn(module, message)for warnings - String format: Use
string.format()for complex strings, avoid concatenation - Auto-sizing: Omit
width/heightproperties (NOTwidth = "auto")
Architecture
- Immediate mode: Elements recreated each frame, layout triggered by
endFrame()→layoutChildren()called on top-level elements - Retained mode: Elements persist, must manually update properties (default)
- Dependencies: Pass via
depstable parameter in constructors (e.g.,{utils, ErrorHandler, Units}). Do not use require outside ofFlexLove.lua. - Layout flow:
Element.new()→layoutChildren()on construction →resize()on viewport change →layoutChildren()again - CSS positioning:
top/right/bottom/leftapplied viaLayoutEngine:applyPositioningOffsets()for absolute/relative containers
Common Patterns
- Return values: Single value OR
value, errorString(nil on success for error) - Enums: Access via
utils.enums.EnumName.VALUE(e.g.,Positioning.FLEX) - Units: Parse with
Units.parse(value)→value, unit, resolve withUnits.resolve(value, unit, viewportW, viewportH, parentSize) - Colors: Use
Color.new(r, g, b, a)(0-1 range) orColor.fromHex("#RRGGBB")