Skip to main content

Crate gizmo_scripting

Crate gizmo_scripting 

Source
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/destroy
  • input — query key and mouse state
  • physics — apply forces and impulses
  • scene — save/load scenes, look up entities
  • audio — play 2D/3D sounds
  • time — 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 scene ComponentRegistry.