Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add gamedata as lua modules root. #1610

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,21 @@ void CScriptEngine::init(ExporterFunc exporterFunc, bool loadGlobalNamespace)
luaL_dostring(lua(), mathRandom);
}

// Adds gamedata folder as module root for lua `require` and allows usage of built-in lua module system.
// Notes:
// - Does not resolve files inside archived game files
// Example:
// `local example = require("scripts.folder.file")` tries to import `gamedata\scripts\folder\file.script`
{
string_path gamedataPath;
string_path packagePath;

FS.update_path(gamedataPath, "$game_data$", "?.script;");
xr_sprintf(packagePath, "package.path = package.path .. [[%s]]", gamedataPath);

luaL_dostring(lua(), packagePath);
}

// XXX nitrocaster: with vanilla scripts, '-nojit' option requires script profiler to be disabled. The reason
// is that lua hooks somehow make 'super' global unavailable (is's used all over the vanilla scripts).
// You can disable script profiler by commenting out the following lines in the beginning of _g.script:
Expand Down
Loading