Can you call “require” a variable?

I have a lua file that will require a different lua file, but I cannot hardcode the file name. Can I use the require function for a variable, or do I need to figure out an alternative approach to what I'm doing?

for instance

local path = "mypath.txt" local level = require path 
+4
source share
1 answer

Yes, you can. require "module" is just syntactic sugar for require("module") , which only works when calling a function with a single argument, which is a string or table constructor. Use the correct call in the form of require(path) and it will work.

+4
source

All Articles