Skip to content

Commit

Permalink
Merge pull request #115 from matheuswhite/58-load-without-extension
Browse files Browse the repository at this point in the history
Allow to load plugin without extension
  • Loading branch information
matheuswhite authored Jul 6, 2024
2 parents 504c10a + 7fd1e6e commit 7dbe1cb
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 7dbe1cb

Please sign in to comment.