Skip to content

Commit

Permalink
feat: allow to load plugin without extension
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuswhite committed Jul 6, 2024
1 parent 504c10a commit 7fd1e6e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::Result;
use chrono::Local;
use homedir::get_my_home;
use mlua::{Function, Lua, RegistryKey, Table, Thread};
use std::ffi::OsStr;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -188,6 +189,9 @@ impl Plugin {
.to_str()
.ok_or("Cannot convert plugin name to string".to_string())?
.to_string();
let extension = filepath.extension().unwrap_or(OsStr::new("lua"));
let filepath = filepath.with_extension(extension);

let code = std::fs::read_to_string(filepath).map_err(|_| "Cannot read plugin file")?;

Self::from_string(name, code)
Expand Down

0 comments on commit 7fd1e6e

Please sign in to comment.