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

Make require check the LUA_PATH environment variable #2122

Closed
mcmanustfj opened this issue Mar 1, 2025 · 1 comment
Closed

Make require check the LUA_PATH environment variable #2122

mcmanustfj opened this issue Mar 1, 2025 · 1 comment
Labels
area-CraftOS This affects CraftOS, or any other Lua portions of the mod. enhancement An extension of a feature or a new feature. wontfix A bug which I won't fix or an enhancement which won't be implemented.

Comments

@mcmanustfj
Copy link

Useful information to include:

  • I want to be able to require("module") the module /modules/module.lua from programs/program.lua.

If there's something I'm missing that lets me do that already, lmk. /rom/modules is read only, so I can't put my own modules there

@mcmanustfj mcmanustfj added the enhancement An extension of a feature or a new feature. label Mar 1, 2025
@SquidDev SquidDev added the area-CraftOS This affects CraftOS, or any other Lua portions of the mod. label Mar 1, 2025
@SquidDev
Copy link
Member

SquidDev commented Mar 1, 2025

require looks up modules using the package.path, which by default looks in:

  • Adjacent to the current program.
  • /rom/modules.

So if your library is stored adjacent (or in a sub-folder) to your actual program, then you can still require it. Alternatively, you can extend the lookup path:

package.path = "/my/libs/?.lua;/my/libs/?/init.lua;" .. package.path

local lib = require "my_fancy_library" -- loads from /my/libs/my_fancy_library.lua

As far as persisting this sort of stuff, CC doesn't have environment variables, so LUA_PATH won't quite work! There have been discussions of other ways to do this (settings, shell API), but I'm not a fan of that approach.

@SquidDev SquidDev closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2025
@SquidDev SquidDev added the wontfix A bug which I won't fix or an enhancement which won't be implemented. label Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CraftOS This affects CraftOS, or any other Lua portions of the mod. enhancement An extension of a feature or a new feature. wontfix A bug which I won't fix or an enhancement which won't be implemented.
Projects
None yet
Development

No branches or pull requests

2 participants