Ask coding questions

← Back to all posts
How do you Require a Lua file with NixOS?
samfierycreeper (8)

How do you Require a Lua file with NixOS?

In my Repl I am trying to require a file, otherfile.lua. The way that I am requiring it would work in Lua normally, but I am using NixOS so that I can use LuaJIT (I might also use LuaSocket later). But instead of getting a file that I can require I get an incredibly long set of errors.

I don't think that this is related to my packages in NixOS. I think that it is just my limited knowledge of NixOS.

I can't really provide alot of details without sounding like a person who's crazy, so I linked a file demonstrating my issue to the post (I think).

You may have to enable show config files to see my .replit file and my NixOS thing

Answered by SixBeeps (5629) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5629)

So apparently in Lua, require() only searches for files in the paths you give it. By default, the current path is not included in this list of paths.

Change the LUA_PATH environment variable to look for scripts in that directory.

samfierycreeper (8)

@SixBeeps Thanks. But one question, I might be really dumb but what is the default path that require() uses on Replit? Because I need to know that to set LUA_PATH to it.

SixBeeps (5629)

@samfierycreeper If you go into the shell and run the command env, it will give you a list of environment variables, including the LUA_PATH.

For you, it looks like it defaulted to this:

samfierycreeper (8)

@SixBeeps one last question. What would I set LUA_PATH to so that I could require() otherfile.lua in my repl?

SixBeeps (5629)

@samfierycreeper Try this: