Skip to main content

ScriptEngine

Struct ScriptEngine 

Source
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

Source

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.

Source

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.

Source

pub fn new() -> Result<Self, LuaError>

Source

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.

Source

pub fn set_memory_limit(&mut self, bytes: usize) -> Result<usize, LuaError>

Change the VM’s heap ceiling in bytes. Returns the previous limit.

Source

pub fn load_script(&mut self, path: &str) -> Result<(), String>

Source

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

Source

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.

Source

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.

Source

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

Source

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)

Source

pub fn reload_if_changed(&mut self, path: &str) -> Result<bool, String>

Script’in hot-reload edilip edilmeyeceğini kontrol eder

Source

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.

Source

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.

Source

pub fn command_queue(&self) -> &Arc<CommandQueue> ⓘ

Komut kuyruğuna doğrudan erişim (internals)

Trait Implementations§

Source§

impl Debug for ScriptEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Sync for ScriptEngine

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more