The PyLua Documentation Portal
Welcome to the official, in-depth documentation for PyLua: a high-performance programming language fusing Lua's lightweight speed, Python's clean imports, C-style curly braces, and an integrated hardware-accelerated 2D Game Engine.
Language Tour in 30 Seconds
-- 1. Python-style imports (No redundant require boilerplate!)
import engine
import vector
import hash
-- 2. Safe Auto-Local scoping (Variables default to local!)
origin = vector.Vector2(0, 0)
target = vector.Vector2(300, 400)
dist = (target - origin):length()
-- 3. C-style curly braces & modern != inequality:
if (dist != 0) {
print("Distance to target: " .. dist .. " pixels")
}
-- 4. Built-in 2D Game Engine (LEngine):
win = engine.Window.create("PyLua Game Showcase", 1280, 720)
world = engine.Physics.createWorld(0, 9.8)
engine.run({
window = win,
physicsWorld = world,
draw = function() {
engine.Graphics.clear(0.1, 0.1, 0.15, 1.0)
engine.Graphics.drawText("Welcome to PyLua!", 40, 40, 2.0, 1.0, 1.0, 1.0, 1.0)
}
})
Documentation Sections
1. Language Syntax & Semantics
Lexical Structure
Character encoding, tokens, comments, identifiers, keywords, and the streaming C99 lexer.
Syntax • 02Type System
16-byte Tagged Values (TValue), numbers, interned strings, tables, and metatables.
Variables & Scoping
The Auto-Local engine, explicit <const> and <close>, upvalues, and _ENV.
Control Flow
Conditionals with {} braces, while, repeat-until, numeric and generic for loops.
Operators
Arithmetic, modern !=, 64-bit bitwise manipulation, short-circuit logic, and precedence table.
Functions & Closures
First-class functions, varargs ..., multiple return values, method sugar :, and tail calls.
Modules & Imports
Python-style import statement, preload table acceleration, and authoring modules.
2. Compiler & Virtual Machine Runtime
Compiler Pipeline
The single-pass recursive descent compiler: Lexer → Parser → CodeGen → Prototype.
Runtime • 02Register-Based VM
Sliding register windows, call frames, and the direct-threaded execution loop in lvm.c.
Opcode Reference
Complete technical breakdown of all 32-bit bytecode instructions (OP_MOVE, OP_CALL, etc.).
Garbage Collector
Tri-color incremental mark-and-sweep, generational GC mode, and write barrier mechanics.
3. Standard Libraries
Base Built-ins
Global functions: print, assert, pcall, xpcall, type, and tostring.
Vector Math
Native vector.Vector2 and Vector3 types with full operator overloads and dot/cross products.
String & UTF-8
Printf-style formatting, linear-time pattern matching, and Unicode UTF-8 codepoints.
StdLib • DataTable Manipulation
In-place sorting, array packing/unpacking, element insertion, and memory slice moves.
StdLib • NumericMath Library
Trigonometry, rounding, IEEE 754 constants, and xoshiro256** pseudo-random generator.
StdLib • SystemI/O & Operating System
Buffered file stream reading, RAII close handles, environment variables, and shell execution.
StdLib • NetworkHTTP Networking
REST API client with request.get() and request.post(), headers, and JSON payloads.
Native GUI Subsystem
Create native desktop windows, buttons, input text fields, and dialog alert boxes.
StdLib • SecurityCryptography & Hash
Compute 128-bit MD5 and 256-bit SHA-2 cryptographic digest hashes.
4. 2D Game Engine (LEngine)
Engine Architecture
The 60+ FPS main loop, frame lifecycle callbacks, and delta-time synchronization.
Engine • WindowWindow & Displays
GLFW windowing, multi-monitor query API, fullscreen toggling, and client resizing.
Engine • RenderGraphics & Rendering
OpenGL 2D immediate-mode rendering for rectangles, circles, lines, sprites, and fonts.
Engine • PhysicsRigid-Body Physics
2D physics worlds, dynamic/static bodies, gravity vectors, velocities, and colliders.
Engine • AudioAudio & Spatial Sound
Low-latency miniaudio sound playback, volume controls, looping, and 3D spatial listener.
Engine • InputInput Handling
Zero-latency keyboard polling, mouse coordinates, button clicks, and GLFW key codes.
Engine • UIIn-Game Immediate UI
Immediate-mode UI buttons, text labels, sliders, and modal backdrop panels.
Engine • AnimationSprite Sheet Animation
Multi-sequence keyframe interpolation, panim format, and the CLI Animator Editor PRO.
Engine • EntityEntity-Script Model
Component-based architecture: attach modular script tables with automatic lifecycle dispatch.
Engine • ThreadsMultithreaded Workers
Spawn parallel OS threads with isolated Lua VM states for background procedural tasks.