pub struct ScriptEngine {
pub log_queue: Arc<Mutex<Vec<(String, String)>>>,
/* private fields */
}Expand description
Lua Scripting Motoru — Genişletilmiş API ile oyun mantığını yönetir
Fields§
§log_queue: Arc<Mutex<Vec<(String, String)>>>Log messages emitted from Lua (print), stored as (level, message) pairs.
Implementations§
Source§impl ScriptEngine
impl ScriptEngine
Sourcepub const DEFAULT_INSTRUCTION_BUDGET: u32 = 2_000_000
pub const DEFAULT_INSTRUCTION_BUDGET: u32 = 2_000_000
Default ceiling for a single call into Lua: on_update for one script, one entity hook,
or the top level of a script being loaded.
Two million instructions is generously above what a per-frame script should ever execute
and far below “the window stopped responding”. It is a runaway guard, not a performance
budget: a script that trips it has a bug, and the alternative to tripping it was hanging
the process, because while true do end in a Lua VM the host has no timeout on is
unrecoverable — no signal, no watchdog, and the frame never ends.
Sourcepub const DEFAULT_MEMORY_LIMIT: usize
pub const DEFAULT_MEMORY_LIMIT: usize
Default ceiling on the VM’s heap. Reached, an allocation fails as a catchable Lua error instead of the process growing until the OOM killer decides which program dies — which on a machine running an editor and a game is not necessarily this one.
pub fn new() -> Result<Self, LuaError>
Sourcepub fn set_instruction_budget(&mut self, instructions: u32)
pub fn set_instruction_budget(&mut self, instructions: u32)
Change the per-call instruction ceiling. Rounded down to a multiple of the hook step, and never to zero — a budget of zero would fail every script on its first hook.
Sourcepub fn set_memory_limit(&mut self, bytes: usize) -> Result<usize, LuaError>
pub fn set_memory_limit(&mut self, bytes: usize) -> Result<usize, LuaError>
Change the VM’s heap ceiling in bytes. Returns the previous limit.
pub fn load_script(&mut self, path: &str) -> Result<(), String>
Sourcepub fn update(
&mut self,
world: &World,
input: &Input,
dt: f32,
) -> Result<(), String>
pub fn update( &mut self, world: &World, input: &Input, dt: f32, ) -> Result<(), String>
Her frame çağrılan güncelleme — World verilerini Lua’ya aktarır, scriptleri çalıştırır
Sourcepub fn declared_properties(
&self,
script_path: &str,
) -> BTreeMap<String, ScriptValue>
pub fn declared_properties( &self, script_path: &str, ) -> BTreeMap<String, ScriptValue>
Per-entity script güncelleme — Script component’i olan entity’ler için izole ortamda çalıştırır
The properties a script DECLARES, read from its properties table.
The convention is a plain assignment at the top of the file:
properties = { open_speed = 2.4, locked = false }which lands in the script’s own environment (_G is that environment — see load_script).
This is the schema and the defaults: the editor lists these names, and an entity that has
not overridden one runs with the declared value.
Anything that is not a number, boolean or string is skipped rather than guessed at — a nested table is a script’s own business and not an inspector row.
Sourcepub fn update_entity(
&mut self,
entity_id: u32,
script_path: &str,
dt: f32,
properties: &BTreeMap<String, ScriptValue>,
) -> Result<(), String>
pub fn update_entity( &mut self, entity_id: u32, script_path: &str, dt: f32, properties: &BTreeMap<String, ScriptValue>, ) -> Result<(), String>
Runs on_entity_update(entity_id, dt, props) for one entity.
properties are that entity’s own values — the third argument exists because scripts are
loaded per PATH, so two entities running the same file share one Lua environment and cannot
each keep a value in it. Passing them is additive: a script whose on_entity_update takes
two parameters simply ignores the third, which is why this did not need a new hook name.
Sourcepub fn flush_commands(&self, world: &mut World, dt: f32) -> Vec<ScriptCommand>
pub fn flush_commands(&self, world: &mut World, dt: f32) -> Vec<ScriptCommand>
Komut kuyruğundaki tüm komutları World’e uygular ve oyun mantığı için kalan komutları döndürür
Sourcepub fn get_pending_audio_scene_commands(&self) -> Vec<ScriptCommand>
pub fn get_pending_audio_scene_commands(&self) -> Vec<ScriptCommand>
Runtime’da bekleyen ses/sahne komutlarını döndürür (demo tarafında ele alınır)
Sourcepub fn reload_if_changed(&mut self, path: &str) -> Result<bool, String>
pub fn reload_if_changed(&mut self, path: &str) -> Result<bool, String>
Script’in hot-reload edilip edilmeyeceğini kontrol eder
Sourcepub fn has_function(&mut self, path: &str, name: &str) -> bool
pub fn has_function(&mut self, path: &str, name: &str) -> bool
Belirli bir isimdeki Lua fonksiyonunun var olup olmadığını kontrol eder
Takes &mut self even though it only reads: registry_value mutates the
underlying lua_State, and the unsafe impl Sync above is only sound
while no &self method reaches the VM.
Sourcepub fn run_entity_update(
&mut self,
path: &str,
func_name: &str,
ctx: &ScriptContext,
) -> Result<ScriptResult, String>
pub fn run_entity_update( &mut self, path: &str, func_name: &str, ctx: &ScriptContext, ) -> Result<ScriptResult, String>
Belirli bir isimdeki Lua fonksiyonunu çağırır (per-entity scriptler için)
Takes &mut self: calling into the VM mutates the lua_State, and the
unsafe impl Sync above is only sound while no &self method does that.
Sourcepub fn command_queue(&self) -> &Arc<CommandQueue> ⓘ
pub fn command_queue(&self) -> &Arc<CommandQueue> ⓘ
Komut kuyruğuna doğrudan erişim (internals)
Trait Implementations§
Source§impl Debug for ScriptEngine
impl Debug for ScriptEngine
impl Sync for ScriptEngine
Auto Trait Implementations§
impl !RefUnwindSafe for ScriptEngine
impl !UnwindSafe for ScriptEngine
impl Freeze for ScriptEngine
impl Send for ScriptEngine
impl Unpin for ScriptEngine
impl UnsafeUnpin for ScriptEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more