Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Require paths don't account for .remodel directory #35

Open
vocksel opened this issue Mar 22, 2021 · 3 comments
Open

Require paths don't account for .remodel directory #35

vocksel opened this issue Mar 22, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@vocksel
Copy link

vocksel commented Mar 22, 2021

Problem I ran into is that keeping my Remodel scripts in the .remodel directory to make it easier to run them results in issues with require().

This is because all paths are relative to the CWD, so you have to write require(".remodel/modulename") from your scripts, but the problem with this is that dots in pathnames cause issues with requiring.

Would be great if Remodel added the .remodel path to where Lua looks for modules so we can simply write require("moduleName").

@LPGhatguy LPGhatguy added the enhancement New feature or request label Mar 22, 2021
@jeparlefrancais
Copy link
Contributor

That'd be pretty neat!

@jeparlefrancais
Copy link
Contributor

I looked into rlua to see if I could just specify new paths for module discovery, but I was not able to find something like that. Would it make senses to just override the require global? If yes I could make something like this, given this directory structure:

  • .remodel
    • foo.lua
    • dependency.lua
    • bar
      • init.lua
      • baz.lua
    • utils
      • copy.lua
Module where require gets called Module it wants How
foo.lua bar require('bar') or require('./bar')
bar/init.lua bar/baz.lua require('./baz') or require('./bar')
bar/baz.lua dependency.lua require('dependency') or require('../dependency')
foo.lua utils/copy.lua require('utils/copy') or require('./utils/copy')

I'd make it so that it looks for modules in:

  • same directory as the file it requires from
  • .remodel directory
  • Current working directory

I don't think I would go with the same . separator as in stock Lua, I think it's clunky to work with. But at the same time it would make it possible to use existing Lua libraries too...

Anyway let me know how does all of that sound!

👋

@LPGhatguy
Copy link
Contributor

You should be able to modify package.path to add the .remodel directory if it exists. I bet we can do that with the rlua API.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants