I am beginning to learn Lua on my own with basically no prior programming knowledge. I understand the basics of types, functions, tables, etc. But in following the Lua tuts at Lua.org, I'm currently on the "Modules Tutorial" and am having issues understanding the proper/easiest way to call a file made into interactive mode.
If I used Notepad++ or Scite to create a file, can someone please help me understand how to open said file using the proper nomenclature to open it?
Assume that your file is named
foo.lua
, then in the Lua interpreter (i.e, the interactive mode), useloadfile
. Note thatloadfile
does not raise error, so it's better to useassert
with it.It will load the chunk in
foo.lua
into the functionf
. Note that this will only load the chunk, not run it. To run it, call the function:If you need to run it immediately, you can use
dofile
:Lua uses
package.path
as the search path which gets its default value fromLUA_PATH
. However, it's better to use proper relative path in practice.