Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a lua program from a text file

Tags:

lua

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.

like image 729
rocksrollsrules Avatar asked Sep 28 '12 00:09

rocksrollsrules


People also ask

How do I run a Lua script in Notepad ++?

On the menu select: Run -> Run.. (F5). Now you can run your scripts by pressing F5 on your keyboard.


1 Answers

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).
like image 132
Mud Avatar answered Nov 22 '22 06:11

Mud