Start sketching out runner runtime

This commit is contained in:
Isaac Clayton 2022-06-01 11:15:06 +02:00
parent 627d067e57
commit 8293b6971d
5 changed files with 114 additions and 0 deletions

7
crates/runner/Cargo.toml Normal file
View file

@ -0,0 +1,7 @@
[package]
name = "runner"
version = "0.1.0"
edition = "2021"
[dependencies]
mlua = { version = "0.8.0-beta.5", features = ["lua54", "vendored"] }

37
crates/runner/src/lib.rs Normal file
View file

@ -0,0 +1,37 @@
use mlua::{Error, FromLua, Lua, ToLua, UserData};
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<Self> {
let lua = Lua::new();
lua.load(&module).exec().ok()?;
return Some(lua);
}
fn interface(&self) -> Self::Interface {
todo!()
}
fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option<V> {
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!()
}
}

View file

@ -0,0 +1,7 @@
use mlua::{Lua, Result};
use runner::*;
pub fn main() {
let lua: Lua = Runtime::init("x = 7".to_string()).unwrap();
}

View file

@ -0,0 +1,22 @@
use mlua::{FromLua, ToLua};
pub trait FromRuntime: Sized {
fn from_runtime() -> Option<Self>;
}
pub trait Interface {
type Handle;
fn handles(&self) -> &[Self::Handle];
}
pub trait Runtime
where
Self: Sized,
{
type Module;
type Interface: Interface;
fn init(plugin: Self::Module) -> Option<Self>;
fn interface(&self) -> Self::Interface;
fn val<'lua, K: ToLua<'lua>, V: FromLua<'lua>>(&'lua self, key: K) -> Option<V>;
}