Skip to content

[LUA] Add custom Lua require loader to resolve modules via the engine file system. - #2121

Open
Neloreck wants to merge 1 commit into
OpenXRay:devfrom
xray-forge:dev-resolve-db-lua-requires
Open

[LUA] Add custom Lua require loader to resolve modules via the engine file system.#2121
Neloreck wants to merge 1 commit into
OpenXRay:devfrom
xray-forge:dev-resolve-db-lua-requires

Conversation

@Neloreck

Copy link
Copy Markdown
Contributor

Notes

  • Extends the gamedata modules root feature ([FEATURE] Add gamedata as lua modules root. #1610), which relied on package.path and could only resolve loose files — scripts packed inside game archives were not visible to require.
  • The loader is registered at package.loaders[2]: after package.preload, before the default package.path loader. On a miss it returns a candidate-path message string instead of raising, so the remaining loaders still run and require error output stays informative.
  • Priority follows the engine file system: loose gamedata files override archived ones (archives are registered first during fsgame.ltx scan, and later registrations win), consistently with how every other game asset is resolved.
  • Loaded chunks are named @<resolved path>, so script stack traces point to real file paths.

Changes

  • Adds gamedata_module_loader — a package.loaders entry that maps require("scripts.folder.file") to gamedata\scripts\folder\file.script and loads it via FS.r_open/luaL_loadbuffer, supporting both loose and archived files.
  • Adds setup_gamedata_module_loading, grouping loader registration and the existing package.path gamedata append into a single setup step.
  • Replaces the inline package.path block in CScriptEngine::init with a setup_gamedata_module_loading call.

…esystem, supporting archived and loose files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant