Skip to content

Commit

Permalink
Lua: Possible fix for 'require' not working in some scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 16, 2024
1 parent 23169b9 commit 517b299
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/mods/ScriptRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,17 @@ void ScriptRunner::reset_scripts() {
std::filesystem::create_directories(autorun_path);
spdlog::info("[ScriptRunner] Loading scripts...");

auto path = std::filesystem::path(autorun_path);
auto dir = path.parent_path();

std::string old_path = m_main_state->lua()["package"]["path"];

std::string package_path = old_path + ";" + dir.string() + "/?.lua";
package_path = package_path + ";" + dir.string() + "/?/init.lua";
package_path = package_path + ";" + dir.string() + "/?.dll";

m_main_state->lua()["package"]["path"] = package_path;

for (auto&& entry : std::filesystem::directory_iterator{autorun_path}) {
auto&& path = entry.path();

Expand Down

0 comments on commit 517b299

Please sign in to comment.