Lua scripting
This commit is contained in:
parent
299daf4e87
commit
44deaa71e1
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -257,6 +257,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"glium",
|
||||
"gltf",
|
||||
"hlua",
|
||||
"nalgebra-glm",
|
||||
]
|
||||
|
||||
@ -504,6 +505,16 @@ 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"
|
||||
@ -618,6 +629,17 @@ 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"
|
||||
|
@ -8,4 +8,5 @@ edition = "2021"
|
||||
glium = "0.31.0"
|
||||
nalgebra-glm = "0.16.0"
|
||||
gltf = { version = "1.0.0", features = ["utils"] }
|
||||
hlua = "0.4.1"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
mod device;
|
||||
mod model;
|
||||
mod scripting;
|
||||
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
@ -7,6 +8,8 @@ extern crate nalgebra_glm as glm;
|
||||
|
||||
use model::Model;
|
||||
|
||||
use scripting::{ ScriptLang, Lua };
|
||||
|
||||
fn main() {
|
||||
use glium::{glutin, Surface};
|
||||
|
||||
@ -29,6 +32,9 @@ fn main() {
|
||||
|
||||
let model = Model::new(&display, "Box.glb");
|
||||
|
||||
let mut script_lang = Lua::new();
|
||||
script_lang.init();
|
||||
|
||||
events_loop.run(move |ev, _, control_flow| {
|
||||
if device_manager.is_pressed(&device::Key::W) {
|
||||
offset += 0.001;
|
||||
|
32
src/scripting.rs
Normal file
32
src/scripting.rs
Normal file
@ -0,0 +1,32 @@
|
||||
extern crate hlua;
|
||||
|
||||
use hlua::Lua as LuaContext;
|
||||
|
||||
pub trait ScriptLang {
|
||||
fn init(&mut self);
|
||||
fn update(&mut self, delta: f32);
|
||||
}
|
||||
|
||||
pub struct Lua {
|
||||
ctx: LuaContext<'static>,
|
||||
}
|
||||
|
||||
impl Lua {
|
||||
pub fn new() -> Self {
|
||||
Lua {
|
||||
ctx: LuaContext::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
fn update(&mut self, delta: f32) {
|
||||
todo!();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user