Skip to content

Commit e7fd88c

Browse files
Cleaned up the code for loading mods
I totally didnt forget to do this like a month ago but its fine chat.
1 parent 22f0829 commit e7fd88c

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/main.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,23 @@ async fn main() {
712712

713713
println!("Loading mods...");
714714
let mod_paths_kinda = std::fs::read_dir("./mods").unwrap();
715-
let mut mod_contents: Vec<String> = vec![];
716715
let mut mods: Vec<Table> = vec![];
717716

718717
// Change this to false to disable the mod loader
719718
let load_mods: bool = true;
720719

721-
// This just puts the contents of all the lua files in a vec
722-
// TODO: Combine the for loops for this and actually loading the mods
720+
let lua = mlua::Lua::new();
721+
722+
// This loads all the mods
723723
for path in mod_paths_kinda {
724724
let path_str = path.unwrap().path().to_str().unwrap().to_string();
725725

726726
let mod_content: String = std::fs::read_to_string(path_str).unwrap();
727727

728-
mod_contents.push(mod_content.clone());
729-
}
728+
let lua_mod: Table = lua.load(mod_content).eval().unwrap();
730729

731-
let lua = mlua::Lua::new();
730+
mods.push(lua_mod);
731+
}
732732

733733
// Exposing stuff to lua
734734
lua.globals().set("velocity_y", velocity_y.clone()).unwrap();
@@ -752,13 +752,6 @@ async fn main() {
752752

753753
lua.globals().set("draw_text", draw_text_lua_func).unwrap();
754754

755-
// Loads the lua mods
756-
for mod_data in mod_contents {
757-
let lua_mod: Table = lua.load(mod_data).eval().unwrap();
758-
759-
mods.push(lua_mod);
760-
}
761-
762755
// This runs all of the setup functions of all the mods
763756
for lua_mod in mods.clone() {
764757
let active: bool = lua_mod.get("enabled").unwrap();

0 commit comments

Comments
 (0)