xmath-usage

Perform in-place xmath mutations on pre-allocated scratch buffers in Defold Lua projects.

81|6|Updated Feb 17, 2026
One-click install
npx skills add https://github.com/indiesoftby/defold-agent-config --skill xmath-usage-indiesoftby
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: xmath-usage
Source: https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/xmath-usage
Command: npx skills add https://github.com/indiesoftby/defold-agent-config --skill xmath-usage-indiesoftby

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

xmath eliminates heap allocations in hot math loops by mutating pre-allocated scratch buffers in place, reducing Lua GC pressure and improving frame time stability.

Core Features & Use Cases

  • In-place mutation: functions write results into the first argument, avoiding new allocations.
  • Scratch buffers: pre-allocate at module scope or init() to reuse across updates.
  • No return values: functions do not return values; chain calls via separate scratch variable steps.
  • Guidance for Defold: use alongside vmath to allocate scratch objects and perform operations via xmath for vector3, vector4, quat, and matrix types.
  • Use Case: optimize a hot path updating an NPC's position by normalizing a direction and applying rotation with minimal allocations.

Quick Start

Create reusable scratch buffers at module scope and perform in-place xmath operations, then apply the final result to your go or math calculations in the hot loop.

Frequently Asked Questions about xmath-usage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I eliminate per-frame heap allocations in Defold Lua math loops?

Use xmath to perform in-place math mutations on pre-allocated scratch buffers, eliminating per-frame heap allocations in Defold Lua. This reduces garbage collection pressure and stabilizes frame times during performance-critical update loops.

How do I set up scratch buffers for zero-allocation math in Defold?

Set up scratch buffers by pre-allocating vector, quaternion, and matrix variables at module scope or within init(). Reuse these pre-allocated variables across update loops to perform in-place xmath operations without triggering heap allocations.

Why do xmath functions not return values in Lua?

xmath functions do not return values because they mutate the first argument in place to avoid heap allocations. You chain operations by using separate scratch variables for each step rather than nesting function calls.

Can I use xmath alongside vmath in Defold for vector and matrix operations?

Yes, you use xmath alongside vmath in Defold. Allocate scratch objects using vmath, then perform in-place zero-allocation operations for vector3, vector4, quat, and matrix types via xmath in your hot paths.

What are the limitations of using zero-allocation math patterns in Defold?

The limitation of zero-allocation math patterns is that xmath functions do not return values, preventing nested call chaining. You must manually manage pre-allocated scratch buffers and write results into the first argument explicitly.