Expand description
Gizmo Scripting — a Lua-based game-logic scripting layer for the Gizmo engine.
Scripts run inside a sandboxed mlua Lua 5.4 VM. Because Lua callbacks
cannot borrow and mutate the ECS World directly, they enqueue changes as
ScriptCommands into a CommandQueue; the ScriptEngine later drains
and applies those commands at a controlled point in the frame.
§Usage
use gizmo_core::input::Input;
use gizmo_core::World;
use gizmo_math::Vec3;
use gizmo_physics_core::Transform;
use gizmo_scripting::ScriptEngine;
let mut world = World::new();
let player = world.spawn();
world.add_component(player, Transform::new(Vec3::ZERO));
let mut script_engine = ScriptEngine::new().unwrap();
script_engine.load_script(&script_path).unwrap(); // e.g. "scripts/player.lua"
// Each frame:
let (input, dt) = (Input::default(), 1.0 / 60.0);
script_engine.update(&world, &input, dt).unwrap(); // runs `on_update`; commands are queued
script_engine.flush_commands(&mut world, dt); // the queue is applied to the World here
// Lua never touched the World itself — the command it enqueued did, at flush time.
let pos = world.borrow::<Transform>().get(player.id()).unwrap().position;
assert_eq!(pos, Vec3::new(1.0, 2.0, 3.0));§Lua API surface
entity— read/write position, rotation, scale, velocity; spawn/destroyinput— query key and mouse statephysics— apply forces and impulsesscene— save/load scenes, look up entitiesaudio— play 2D/3D soundstime— delta time, elapsed time, FPS
Re-exports§
pub use commands::CommandQueue;pub use commands::ScriptCommand;pub use engine::Script;pub use engine::ScriptContext;pub use engine::ScriptEngine;pub use engine::ScriptResult;pub use engine::ScriptValue;
Modules§
- api_ai
- AI API — Lua’ya sunulan Yapay Zeka navigasyon fonksiyonları
- api_
audio - Audio API — Lua’ya sunulan ses yönetim fonksiyonları
- api_
entity - Entity API — Lua’ya sunulan entity yönetim fonksiyonları
- api_
fighter - Fighter API — Lua’ya sunulan dövüş sistemi fonksiyonları
- api_
input - Input API — Lua’ya sunulan girdi sorgulama fonksiyonları
- api_
physics - Physics API — Lua’ya sunulan fizik sistemi fonksiyonları
- api_
scene - Scene API — Lua’ya sunulan sahne ve oyun yönetim fonksiyonları
- api_
table - API tables a script can read and cannot rewrite.
- api_
time - Time API — Lua’ya sunulan zaman fonksiyonları
- api_
vehicle - Vehicle API — Lua’ya sunulan araç kontrol fonksiyonları
- commands
- Script Command Queue — Lua scriptlerden gelen değişiklik isteklerinin biriktirildiği kuyruk
- engine
Functions§
- register_
script_ components - Registers the scripting layer’s serializable scene components (currently
Script) into a sceneComponentRegistry.