Use mlua in place of hlua (more lua versions)

This commit is contained in:
Dane Johnson 2022-04-11 15:16:46 -05:00
parent 44deaa71e1
commit b5e4ce3ddb
3 changed files with 39 additions and 31 deletions

52
Cargo.lock generated
View File

@ -77,6 +77,15 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"memchr",
]
[[package]]
name = "bumpalo"
version = "3.9.1"
@ -257,7 +266,7 @@ version = "0.1.0"
dependencies = [
"glium",
"gltf",
"hlua",
"mlua",
"nalgebra-glm",
]
@ -505,16 +514,6 @@ dependencies = [
"gl_generator",
]
[[package]]
name = "hlua"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed9db71fff2e55b83d24bbbdd9ad13f0d1ff79bc265f544370f39ee0825d54e4"
dependencies = [
"libc",
"lua52-sys",
]
[[package]]
name = "ident_case"
version = "1.0.1"
@ -629,17 +628,6 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "lua52-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d451db153c94e455dc817d388f9674f6232425c28db3509e90251c55b8df2f94"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -730,6 +718,20 @@ dependencies = [
"winapi",
]
[[package]]
name = "mlua"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29e2194305aa8301d5da9c1c98640047f4219f6b95c190f6860338ab9872b686"
dependencies = [
"bstr",
"cc",
"num-traits",
"once_cell",
"pkg-config",
"rustc-hash",
]
[[package]]
name = "nalgebra"
version = "0.30.1"
@ -1070,6 +1072,12 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.9"

View File

@ -8,5 +8,4 @@ edition = "2021"
glium = "0.31.0"
nalgebra-glm = "0.16.0"
gltf = { version = "1.0.0", features = ["utils"] }
hlua = "0.4.1"
mlua = { version = "0.7.4", features = ["lua54"] }

View File

@ -1,6 +1,6 @@
extern crate hlua;
extern crate mlua;
use hlua::Lua as LuaContext;
use mlua::Lua as LuaContext;
pub trait ScriptLang {
fn init(&mut self);
@ -8,22 +8,23 @@ pub trait ScriptLang {
}
pub struct Lua {
ctx: LuaContext<'static>,
ctx: LuaContext,
}
impl Lua {
pub fn new() -> Self {
let ctx = LuaContext::new();
Lua {
ctx: LuaContext::new(),
ctx,
}
}
}
impl ScriptLang for Lua {
fn init(&mut self) {
self.ctx.openlibs();
//self.ctx.execute::<()>("print(\"Hello!\")").unwrap();
self.ctx.execute_from_reader::<(), std::fs::File>(std::fs::File::open(&std::path::Path::new("main.lua")).unwrap()).unwrap();
let path = std::path::Path::new("main.lua");
let buf = std::fs::read(&path).expect("Could not find main.lua");
self.ctx.load(&buf).exec();
}
fn update(&mut self, delta: f32) {