diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index 802755c961..d305f092d5 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -1,12 +1,12 @@ -use mlua::{Error, FromLua, Lua, ToLua, UserData}; +use std::collections::{HashMap, HashSet}; + +use mlua::{Error, FromLua, Function, Lua, ToLua, UserData, Value}; pub mod runtime; pub use runtime::*; impl Runtime for Lua { type Module = String; - // type Error = Error; - type Interface = LuaInterface; fn init(module: Self::Module) -> Option { let lua = Lua::new(); @@ -14,24 +14,14 @@ impl Runtime for Lua { return Some(lua); } - fn interface(&self) -> Self::Interface { - todo!() - } + fn interface(&self) -> Interface { + let mut globals = HashSet::new(); + for pair in self.globals().pairs::() { + if let Ok((k, _)) = pair { + globals.insert(k); + } + } - fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option { - self.globals().get(key).ok() - } -} - -pub struct LuaInterface { - funs: Vec, - vals: Vec, -} - -impl Interface for LuaInterface { - type Handle = String; - - fn handles(&self) -> &[Self::Handle] { - todo!() + globals } } diff --git a/crates/runner/src/main.rs b/crates/runner/src/main.rs index d9ad57ecae..c82e245619 100644 --- a/crates/runner/src/main.rs +++ b/crates/runner/src/main.rs @@ -4,4 +4,14 @@ use runner::*; pub fn main() { let lua: Lua = Runtime::init("x = 7".to_string()).unwrap(); + println!("{:?}", lua.interface()); +} + +struct InterfaceX; + +impl InterfaceX { + pub fn get_x(runtime: T) -> usize { + // runtime.get("x") + todo!() + } } diff --git a/crates/runner/src/runtime.rs b/crates/runner/src/runtime.rs index 921c274719..8436e29da7 100644 --- a/crates/runner/src/runtime.rs +++ b/crates/runner/src/runtime.rs @@ -1,22 +1,17 @@ -use mlua::{FromLua, ToLua}; +use std::collections::HashSet; -pub trait FromRuntime: Sized { - fn from_runtime() -> Option; -} +use mlua::{FromLua, Lua, ToLua, Value}; -pub trait Interface { - type Handle; - fn handles(&self) -> &[Self::Handle]; -} +pub type Interface = HashSet; pub trait Runtime where Self: Sized, { type Module; - type Interface: Interface; fn init(plugin: Self::Module) -> Option; - fn interface(&self) -> Self::Interface; - fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option; + fn interface(&self) -> Interface; + // fn val<'a, T>(&'a self, name: String) -> Option; + // fn call<'a, A: MyFromLua<'a>, R>(&'a mut self, name: String, arg: A) -> Option; }