Take the 2-minute tour ×

I have directory that contain multiple file i need to load on specified file.

i know i can use loadfile(path) but how i need to specify which file to load thank you Jp

share|improve this question
In this context, the word "path" means "pathname of a file", not specifically "path to a file". –  RBerteig Feb 5 '11 at 5:41

2 Answers 2

up vote 4 down vote accepted

I'm not 100% sure I understand what you are asking, but here's my take on it. If you know the directory you need to load the file from, you'd just prefix it to the name of the file:

local f, error = loadfile(mydir .. "/my_file")

Note that this reads and parses the file. To actually execute it, you need to invoke the function you get back from loadfile() (so f() in this example). If there is an error, loadfile() returns nil and an error message.

share|improve this answer
path = "./path/to/a/file.lua"
local myreturn1, myreturn2 --[[etc]] = assert(loadfile(path))(myarg1, myarg2, myarg3 --[[etc]])
share|improve this answer

Your Answer


