rocksrollsrules
rocksrollsrules

Reputation: 117

Running a lua program from a text file

I've just started learning Lua, and I'm trying to get the native Lua interpreter to run a program that has been saved to a .txt file. I'm running Windows Vista with Lua 5.1.4.

Perhaps I'm missing something, but the only thing my book (Programming in Lua) says is that all you have to do to run your program is to call the interpreter with the name of the text file that contains your program. Then it gives this supposedly handy piece of code:

% lua filename.lua

Which I can't get to work in cmd or in the Lua interpreter. Further research I've done indicates that I might need to use a

dofile("filename.lua")

command, but I'm not sure how to do this. Specifically, what information do I need to put in the argument? Any help you can give is greatly appreciated.

Upvotes: 7

Views: 49284

Answers (1)

Mud
Mud

Reputation: 28991

You need to download a Win32 binary (see lua-5.2.1_Win32_bin.zip or lua-5.2.1_Win64_bin.zip here). Unzip this somewhere. How to run your script, in order of easiness and inverse order or common procedure:

  1. Drag your script onto the Lua.exe using the Windows file Explorer.

  2. a. Move your script to the same folder as Lua.exe
    b. Shift right-click on that folder and select Open Command Window Here.
    c. Type lua filename.lua and press Enter.

  3. Add the directory containing Lua.exe to your system PATH, then do steps 2a and 2b on the folder containing your script.

  4. Integrate Lua.exe with your editor in some way (how you do this depends on your editor).

Upvotes: 7

Related Questions