Clean up interface a bit
This commit is contained in:
+11
-21
@@ -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 mod runtime;
|
||||||
pub use runtime::*;
|
pub use runtime::*;
|
||||||
|
|
||||||
impl Runtime for Lua {
|
impl Runtime for Lua {
|
||||||
type Module = String;
|
type Module = String;
|
||||||
// type Error = Error;
|
|
||||||
type Interface = LuaInterface;
|
|
||||||
|
|
||||||
fn init(module: Self::Module) -> Option<Self> {
|
fn init(module: Self::Module) -> Option<Self> {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
@@ -14,24 +14,14 @@ impl Runtime for Lua {
|
|||||||
return Some(lua);
|
return Some(lua);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Self::Interface {
|
fn interface(&self) -> Interface {
|
||||||
todo!()
|
let mut globals = HashSet::new();
|
||||||
}
|
for pair in self.globals().pairs::<String, Value>() {
|
||||||
|
if let Ok((k, _)) = pair {
|
||||||
|
globals.insert(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option<V> {
|
globals
|
||||||
self.globals().get(key).ok()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct LuaInterface {
|
|
||||||
funs: Vec<String>,
|
|
||||||
vals: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Interface for LuaInterface {
|
|
||||||
type Handle = String;
|
|
||||||
|
|
||||||
fn handles(&self) -> &[Self::Handle] {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,14 @@ use runner::*;
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let lua: Lua = Runtime::init("x = 7".to_string()).unwrap();
|
let lua: Lua = Runtime::init("x = 7".to_string()).unwrap();
|
||||||
|
println!("{:?}", lua.interface());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InterfaceX;
|
||||||
|
|
||||||
|
impl InterfaceX {
|
||||||
|
pub fn get_x<T: Runtime>(runtime: T) -> usize {
|
||||||
|
// runtime.get("x")
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
use mlua::{FromLua, ToLua};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub trait FromRuntime: Sized {
|
use mlua::{FromLua, Lua, ToLua, Value};
|
||||||
fn from_runtime() -> Option<Self>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Interface {
|
pub type Interface = HashSet<String>;
|
||||||
type Handle;
|
|
||||||
fn handles(&self) -> &[Self::Handle];
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Runtime
|
pub trait Runtime
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
type Module;
|
type Module;
|
||||||
type Interface: Interface;
|
|
||||||
|
|
||||||
fn init(plugin: Self::Module) -> Option<Self>;
|
fn init(plugin: Self::Module) -> Option<Self>;
|
||||||
fn interface(&self) -> Self::Interface;
|
fn interface(&self) -> Interface;
|
||||||
fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option<V>;
|
// fn val<'a, T>(&'a self, name: String) -> Option<T>;
|
||||||
|
// fn call<'a, A: MyFromLua<'a>, R>(&'a mut self, name: String, arg: A) -> Option<R>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user