diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 15:41:31 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-10 15:41:31 +0200 |
| commit | b747ca8af52129876b577a4f20f7105a05c6b002 (patch) | |
| tree | d976a5c3cd135dfecb1014246936bb7a8b525c4b /src/lua | |
| parent | 4763d8ce3b833df1e7321a407b08666f69657fdb (diff) | |
add global fileloader registry
Diffstat (limited to 'src/lua')
| -rw-r--r-- | src/lua/runnable.rs | 4 | ||||
| -rw-r--r-- | src/lua/runtime.rs | 17 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/lua/runnable.rs b/src/lua/runnable.rs index adda512..683d191 100644 --- a/src/lua/runnable.rs +++ b/src/lua/runnable.rs @@ -5,6 +5,7 @@ use super::ownedfunction::OwnedFunction; pub trait Runnable<A, R> where Self: Send, + R: ?Sized { fn run<'lua>(&self, arg: A, lua: &'lua Lua) -> Result<R> where @@ -16,6 +17,7 @@ impl<A, R, T> Runnable<A, R> for T where T: Fn(A) -> R, Self: Send, + R: ?Sized { fn run<'lua>(&self, arg: A, _: &'lua Lua) -> Result<R> where @@ -29,6 +31,7 @@ where impl<A, R> Runnable<A, R> for OwnedFunction where Self: Send, + R: ?Sized { fn run<'lua>(&self, arg: A, lua: &'lua Lua) -> Result<R> where @@ -39,4 +42,3 @@ where func.call::<A, R>(arg) } } - diff --git a/src/lua/runtime.rs b/src/lua/runtime.rs index ce34827..6a0a230 100644 --- a/src/lua/runtime.rs +++ b/src/lua/runtime.rs @@ -3,14 +3,15 @@ use std::time::{SystemTime, UNIX_EPOCH}; use crate::{ config::{self, GlobalConfig}, - sheet::register::Register, state::GlobalState, + sheet::{loader::Loader, register::Register}, + state::GlobalState, }; pub fn neosheet(lua: &Lua) -> Result<()> { let exports = lua.create_table()?; exports - .set("sheets", lua.create_userdata(Register)?) + .set("sheet", lua.create_userdata(Register)?) .unwrap(); exports .set("config", lua.create_userdata(GlobalConfig::default())?) @@ -18,6 +19,9 @@ pub fn neosheet(lua: &Lua) -> Result<()> { exports .set("state", lua.create_userdata(GlobalState::default())?) .unwrap(); + exports + .set("loader", lua.create_proxy::<Loader>()?) + .unwrap(); lua.globals() .get::<_, Table>("package")? @@ -45,10 +49,15 @@ pub fn package(lua: &Lua) -> Result<()> { package.set( "path", format!( - "{}/?.lua;{}/?/init.lua;{};./?.lua", + "{}/?.lua;{}/?/init.lua;{}/lib/?.lua;{}/lib/?/init.lua;{};./?.lua", + config::constants::USER_CONFIG_DIR.as_str(), + config::constants::USER_CONFIG_DIR.as_str(), config::constants::USER_CONFIG_DIR.as_str(), config::constants::USER_CONFIG_DIR.as_str(), - path.split(';').filter(|s| s.starts_with('/')).collect::<Vec<&str>>().join(";"), + path.split(';') + .filter(|s| s.starts_with('/')) + .collect::<Vec<&str>>() + .join(";"), ), )?; Ok(()) |