use super::{RuntimeEngine, RuntimeResult, RuntimeValue, RuntimeStats, RuntimeConfig};
use std::collections::HashMap;
pub struct LuaRuntime {
#[allow(dead_code)]
config: RuntimeConfig,
stats: RuntimeStats,
functions: HashMap<String, String>,
}
impl LuaRuntime {
pub fn new(config: RuntimeConfig) -> RuntimeResult<Self> {
Ok(Self {
config,
stats: RuntimeStats {
memory_used: 0,
functions_executed: 0,
total_execution_time_ms: 0,
gc_collections: 0,
},
functions: HashMap::new(),
})
}
}
impl RuntimeEngine for LuaRuntime {
fn execute(&mut self, function_name: &str, _args: &[RuntimeValue]) -> RuntimeResult<RuntimeValue> {
use super::RuntimeError;
Err(RuntimeError::LuaError(format!(
"Lua runtime is provided by embedding application. \
Function '{}' should be executed via DataSource.execute_lua_function(). \
When using HyperQL in Hyperspatial, compute functions are available through RouterDataSource.",
function_name
)))
}
fn load_function(&mut self, name: &str, code: &str) -> RuntimeResult<()> {
self.functions.insert(name.to_string(), code.to_string());
Ok(())
}
fn has_function(&self, name: &str) -> bool {
self.functions.contains_key(name)
}
fn get_stats(&self) -> RuntimeStats {
self.stats.clone()
}
}
#[derive(Debug, Clone)]
pub struct LuaConfig {
pub enable_jit: bool,
pub gc_pause: i32,
pub gc_stepmul: i32,
pub max_instructions: u64,
}
impl Default for LuaConfig {
fn default() -> Self {
Self {
enable_jit: true,
gc_pause: 200,
gc_stepmul: 200,
max_instructions: 1_000_000,
}
}
}