pub struct LuaEngine { /* private fields */ }Expand description
The Lua scripting engine. Thread-safe, cheaply cloneable.
Holds a pool of pre-initialized Lua states (one per worker) for global scripts, plus per-script pools for route-specific scripts.
Implementations§
Source§impl LuaEngine
impl LuaEngine
Sourcepub fn new(
scripts_dir: &Path,
num_states: usize,
hook_timeout: Duration,
) -> Result<Self>
pub fn new( scripts_dir: &Path, num_states: usize, hook_timeout: Duration, ) -> Result<Self>
Create a new LuaEngine by loading all .lua files from scripts_dir.
num_states should match the number of worker threads.
hook_timeout is the max execution time per hook call.
Sourcepub fn with_route_scripts(
scripts_dir: &Path,
num_states: usize,
hook_timeout: Duration,
global_scripts: &[String],
route_script_names: &[String],
) -> Result<Self>
pub fn with_route_scripts( scripts_dir: &Path, num_states: usize, hook_timeout: Duration, global_scripts: &[String], route_script_names: &[String], ) -> Result<Self>
Create a LuaEngine with per-route script support.
global_scripts — filenames loaded into the global pool (run on every request)
route_script_names — unique filenames that need their own per-worker pools
pub fn has_on_request(&self) -> bool
pub fn has_on_route(&self) -> bool
pub fn has_on_response(&self) -> bool
pub fn has_on_request_end(&self) -> bool
Sourcepub fn call_on_request(&self, req: &mut LuaRequest) -> RequestHookResult
pub fn call_on_request(&self, req: &mut LuaRequest) -> RequestHookResult
Call on_request(req). Returns Continue or Deny.
Sourcepub fn call_route_on_request(
&self,
script_name: &str,
req: &mut LuaRequest,
) -> RequestHookResult
pub fn call_route_on_request( &self, script_name: &str, req: &mut LuaRequest, ) -> RequestHookResult
Call on_request for a specific route script. Returns Continue or Deny.
Sourcepub fn call_on_route(
&self,
req: &LuaRequest,
matched_target: &str,
) -> RouteHookResult
pub fn call_on_route( &self, req: &LuaRequest, matched_target: &str, ) -> RouteHookResult
Call on_route(req, matched_target). Returns Override(url) or Default.
Sourcepub fn call_route_on_route(
&self,
script_name: &str,
req: &LuaRequest,
matched_target: &str,
) -> RouteHookResult
pub fn call_route_on_route( &self, script_name: &str, req: &LuaRequest, matched_target: &str, ) -> RouteHookResult
Call on_route for a specific route script.
Sourcepub fn call_on_response(
&self,
req: &LuaRequest,
status: u16,
headers: &HashMap<String, String>,
) -> ResponseMod
pub fn call_on_response( &self, req: &LuaRequest, status: u16, headers: &HashMap<String, String>, ) -> ResponseMod
Call on_response(req, resp). Returns ResponseMod with any changes.
Sourcepub fn call_route_on_response(
&self,
script_name: &str,
req: &LuaRequest,
status: u16,
headers: &HashMap<String, String>,
) -> ResponseMod
pub fn call_route_on_response( &self, script_name: &str, req: &LuaRequest, status: u16, headers: &HashMap<String, String>, ) -> ResponseMod
Call on_response for a specific route script.
Sourcepub fn call_on_request_end(
&self,
req: &LuaRequest,
status: u16,
duration_ms: f64,
target: &str,
)
pub fn call_on_request_end( &self, req: &LuaRequest, status: u16, duration_ms: f64, target: &str, )
Call on_request_end(req, resp_status, duration_ms).
Sourcepub fn call_route_on_request_end(
&self,
script_name: &str,
req: &LuaRequest,
status: u16,
duration_ms: f64,
target: &str,
)
pub fn call_route_on_request_end( &self, script_name: &str, req: &LuaRequest, status: u16, duration_ms: f64, target: &str, )
Call on_request_end for a specific route script.
Sourcepub fn has_route_script(&self, name: &str) -> bool
pub fn has_route_script(&self, name: &str) -> bool
Check if a route script is loaded.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LuaEngine
impl RefUnwindSafe for LuaEngine
impl Send for LuaEngine
impl Sync for LuaEngine
impl Unpin for LuaEngine
impl UnsafeUnpin for LuaEngine
impl UnwindSafe for LuaEngine
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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