Suppose your file is named foo.lua , then in the Lua interpreter (i.e. interactively) use loadfile . Please note that loadfile does not cause an error, so it is better to use assert with it.
f = assert(loadfile("foo.lua"))
It will load the piece in foo.lua into the function f . Please note that this will only load the piece, not run it. To start it, call the function:
f()
If you need to run it immediately, you can use dofile :
dofile("foo.lua")
Lua uses package.path as the search path, which gets the default value from LUA_PATH . However, in practice, it is better to use the correct relative path.
source share