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

41
Cargo.lock generated
View File

@ -2627,6 +2627,24 @@ dependencies = [
"url",
]
[[package]]
name = "lua-src"
version = "544.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "708ba3c844d5e9d38def4a09dd871c17c370f519b3c4b7261fbabe4a613a814c"
dependencies = [
"cc",
]
[[package]]
name = "luajit-src"
version = "210.3.4+resty073ac54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "640b09e99575a442b4da0ef406a78188a1a4313bb9ead7b5b20ec12cc480130f"
dependencies = [
"cc",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -2845,6 +2863,22 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "mlua"
version = "0.8.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bb054c5769e1aeb137554b95941e997b62d17f5265bef213cb63179d75a6bf6"
dependencies = [
"bstr",
"cc",
"lua-src",
"luajit-src",
"num-traits",
"once_cell",
"pkg-config",
"rustc-hash",
]
[[package]]
name = "multimap"
version = "0.8.3"
@ -3971,6 +4005,13 @@ dependencies = [
"zeroize",
]
[[package]]
name = "runner"
version = "0.1.0"
dependencies = [
"mlua",
]
[[package]]
name = "rust-embed"
version = "6.4.0"

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>;
}