Lua scripting

This commit is contained in:
2022-04-09 12:42:18 -05:00
parent 299daf4e87
commit 44deaa71e1
5 changed files with 62 additions and 0 deletions

View File

@@ -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
View 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!();
}
}