You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
use rlua::{Lua, Context, Error};
|
|
use crate::maps::init_lua;
|
|
use crate::types::{Bind, Action, Handler};
|
|
use crate::config::Config;
|
|
use std::default::Default;
|
|
|
|
pub fn load_config(lua_config: &str) -> Result<Config, Error> {
|
|
let lua = Lua::new();
|
|
|
|
let bind: Result<_, Error> = lua.context(|c: Context| {
|
|
init_lua(c)?;
|
|
|
|
let g = c.globals();
|
|
|
|
let mut config = Config::default();
|
|
|
|
c.scope::<_, Result<_, Error>>(|scope| {
|
|
g.set("sync", scope.create_function_mut(|_: Context, args: (Bind, Bind, Option<bool>)| {
|
|
println!("config -> sync({:?}, {:?}, {:?})", args.0, args.1, args.2);
|
|
config
|
|
.binds
|
|
.insert(args.0, Handler {
|
|
action: Action::Sync(args.1),
|
|
passthrough: args.2.unwrap_or(false),
|
|
});
|
|
|
|
Ok(())
|
|
})?)?;
|
|
|
|
c.load(lua_config).exec()?;
|
|
|
|
Ok(())
|
|
})?;
|
|
|
|
Ok(config)
|
|
});
|
|
|
|
Ok(bind?)
|
|
} |