Commands and applications

1. Introduction and preliminary

The exercises here will help you understand a little of the way MS-Windows commands work and get you used to the command prompt or terminal window. You can use almost any disk or drive that you have access to, but because of the way MS-Windows remaps folders on the C: drive, the main C: drive is really NOT suitable. I will assume you are using the U: drive. If you use a different one replace "U" by the drive letter throughout.

To get started do the following.

2. Executable files

Executable files, also called apps or applications, are special files with the extension ".exe". MS-Windows can run these as "commands" in certain ways. Some of the ways to run these commands involve the mouse, and in this case MS-Windows does not tell you what it is doing. We will start with something that is rather slow and cumbersome but will be clear and easy to understand what is going on, and which is particularly useful when you need complete control over the system.

The plan is to run the "hello.lua" file with a command called "lua53.exe".

Do this:

Notes:

"lua53.exe" contains an app called lua53.exe, which can much of the time also be called "lua53". The "lua53.dll" is a "helper" file that is necessary for the app to run. On windows, most apps need dll files like this. These files are prepared in such a way that it should work on all recent 64-bit MS-Windows computers. It will not work on 32-bit systems, nor on other systems, but versions of this file can be got for most systems.

I obtained these files from http://luabinaries.sourceforge.net/. If you want to get a version for a different computer, or see if there is a more recent version, go to that site, click "download" on the left and select a zip file for the computer you use.

Note that ".exe" files and ".dll" files can in principle contain "viruses". On MS-Windows, you should run anti-virus programs and scan such files you download like this. On other systems this is much less of a problem for lots of reasons. I strongly believe the file I just provided is OK (and have implemented ways to detect if it gets changed in any malicious way) so there is nothing much to be concerned about here, provided of course you trust me. But in general caution is needed.

The lua53 app can be started by double clicking it in Explorer. We'll talk about this later. In the meantime if you did this just close the window. (The key sequence control-Z followed by enter does this.)

3. The command line

Essentially, MS-Windows works by issuing "commands" to itself in response to mouse and keyboard clicks. You can get direct access to at least some of these commands by opening a "command line shell", or "terminal window". (Again these terms are essentially synonymous.) The "command line shell" was improved for Windows 10, but before that was little changed from the old MS-DOS days and this was one of the very weakest points of MS-Windows. Mac and linux have significantly better shells, but the Windows 10 one is good enough for us here.

Do this:

The window that appears (usually black with white text) accepts characters that you type. In all cases you need to type a command in one line and then press the enter key. Most of the time I will omit to say "and press enter" in these instructions because it is expected that you do it for every command.

Do this:

If you accidentally named any of the folders incorrectly earlier on, some of this won't work. If you deliberately changed the names then of course you should use the names you chose, not mine.

At this point there are a number of commands you can do that might be useful.

Note that how a command works will depend critically on which drive you are on and which folder of that drive you are at. (Helpfully, the command prompt tells you this information at all times!) If you are still unsure where you are or what the contents of the folder is, the "dir" command is a useful fallback for more information.

Do this:

Almost certainly a lot of this was new to you and some of it might have been confusing or difficult to remember. So please then go over it all over again and repeat.

It is also a good idea to keep a notebook and make a note of all the important and useful commands and procedures that you think might be useful in the future.

4. Other ways of running lua53

lua53.exe is an application and can be run directly from the Windows Explorer by double clicking it. What this does is generate and run the command "lua53.exe" without the "hello.lua" part, and runs this command in the folder you see. If that is good enough for you then all is fine. Otherwise you need to find more precise ways for runing special commands. In general this depends on the application and what you want to do.

As it happens, for the next particular example, double clicking "lua53.exe" is good enough.

If you run lua53 in this way you get something similar to (but not the same as) the command prompt and you can start typing lua commands in this window if you know what you want to type.

Do this now: double click lua53.exe.

You should get a window coming up that looks very like the cmd.exe window but with a message about lua and a slightly different prompt that looks like ">" on its own.

Note that this window doesn't accept the old commands. (It works in a different "language", i.e. the Lua language, not the MS-Windows shell language.) Most of the old commands you saw before (such as "cd") just generate error messages.

Lua is a programming language and the main use of it is to run commands in this particular language. So you can type things like "print(1+1)" and get the answer 2. You can also load and run a file in lua with something like "dofile("hello.lua")" provided that the file you want is in the correct directory.

Try these now.

Of course Lua is a completely different language to the shell, so there are new things to learn, but it is a lot more powerful than the MS-Windows shell in many ways, especially for programming and calculations.

If you want to quit lua type "os.exit()" (followed by enter) or else (in MS-Windows) press control-Z followed by enter. (On Macs or under linux, "os.exit()" still works, but if you prefer, control-D will quit.)

If something goes wrong and you need to get back control from something that is "stuck", then "Esc" or control-C are usually the key presses to try. ("Esc" may not work, but control-C is more or less universal across all systems.)

The next few sections of these web notes concern how to write simple scripts and programs in lua.