Skip to content

lua

This directory provides Talon voice-coding support for the Lua programming language. It defines standard programming patterns, language keywords, built-in functions, library structures, and style rules tailored for writing Lua scripts efficiently.

Core Language Support

The Python file lua.py implements the backend behavior for Lua context matching, environment configuration, and code formatting:

  • Version-Sensitive Operators: It registers a lua_version setting (defaulting to 5.1). Based on this version, bitwise operators will adjust dynamically. For version 5.3 and higher, it outputs modern native operators (such as & or ~); for older versions, it falls back to library-based calls like bit.band() and bit.xor().
  • Action Implementations: It overrides standard user actions to match Lua's syntax requirements, such as block comments (--[[ ... --]]), boolean values (true and false), null representations (nil), and localized functions (local function name() ... end).
  • Libraries and Objects: Defines common Lua libraries (like utf8, table, math, os, and socket) to facilitate quick syntax construction.

Syntax Rules and Spoken Commands

The grammar and specific formatting controls are declared in lua.talon. When a file with the .lua extension is active, this file automatically loads and configures the editor environment:

  • Standard Styling: Configures standard variable and function formatters to use SNAKE_CASE as is common in the Lua community.
  • Tag Activation: Integrates Lua with general community programming tags, including imperative code structures, math operations, and key-value pairings.
  • Custom Constructs: Provides spoken triggers for fast syntax assembly. For example:
    • "state local variable" inserts a local variable formatted in snake case.
    • "method <text>" formats a colon-based method call on an object (e.g., :gsub()).
    • "require <library>" automates inserting import/require statement snippets.
    • "state return true/false" inserts instant return conditions.

Vocabulary and Auto-completions

To ensure you can speak standard language constructs and built-in library methods easily, the environment uses list mapping files:

Code Formatter Integration

If you use StyLua to maintain clean styling, enabling the user.stylua tag will activate the commands inside stylua.talon. This allows you to speak voice commands to wrap code lines or code blocks with native StyLua ignore comments:

  • -- stylua: ignore
  • -- stylua: ignore start / -- stylua: ignore end