PyLua 2D Game Engine (LEngine)

PyLua integrates a native, hardware-accelerated 2D game framework directly into the language runtime. It bundles OpenGL graphics, 2D rigid-body physics, low-latency audio via miniaudio, immediate-mode UI, and multithreaded worker threads.

1. The Unity-Inspired Game Loop (`engine.run`)

The engine coordinates GLFW events, updates physics simulations, executes script entity updates, and swaps frame buffers in a single unified game loop:

game_main.lua
import engine

-- 1. Create a 1280x720 window:
win = engine.Window.create("PyLua 2D Action", 1280, 720)

-- 2. Create physics world with gravity:
world = engine.Physics.createWorld(0, 9.8)

-- 3. Run the engine loop:
engine.run({
    window = win,
    physicsWorld = world,

    init = function() {
        print("Game Initialized!")
        playerX = 100
        playerY = 100
    },

    update = function(dt) {
        -- Smooth movement scaled by delta time:
        if (engine.Input.isKeyDown(262)) { playerX = playerX + 200 * dt } -- Right Arrow
        if (engine.Input.isKeyDown(263)) { playerX = playerX - 200 * dt } -- Left Arrow
    },

    draw = function() {
        -- Clear screen to dark slate:
        engine.Graphics.clear(0.1, 0.12, 0.18, 1.0)

        -- Render player character:
        engine.Graphics.drawRect(playerX, playerY, 48, 48, 0.2, 0.6, 1.0, 1.0)
    }
})

2. Engine Subsystems Overview