Skip to content

Commit

Permalink
[FEATURE] Add gamedata as lua modules root. (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloreck authored Dec 27, 2024
1 parent 33cf4c9 commit 6adea8e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,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

0 comments on commit 6adea8e

Please sign in to comment.