- Lua Quick Start Guide
- Gabor Szauer
- 446字
- 2021-08-05 10:30:34
Hello World!
It is common practice when first learning a new programming language to create a Hello World program. This is a simple program that prints the words Hello World to the screen. The goal of this exercise is to write, compile (or interpret), and run a simple piece of code to prove that you can execute it.
The program will be written using Visual Studio Code, but how will it be executed? Visual Studio Code provides an Integrated Terminal. This is a Terminal that should work the same way regardless of what operating system you are using. It's important to note that whatever code gets executed through this Terminal can also be executed through the operating system Terminal/shell.
Being able to perform the same steps regardless of operating system can save time and reduce errors. For this reason, future chapters will assume code will be executed in VS Code instead of the native Terminal of each operating system.
Follow these steps to create a Hello World program, save it, and execute it on any platform (macOS, Windows 10, or Linux):
- Open Visual Studio Code and make a new document with File > New.
- Set the syntax highlighting of this file to the Lua syntax. Click on the Plain Text label in the bottom right of the code tab, then select Lua (lua) from the drop-down menu that appears:

- In this new file, type print ('hello, world'):

- Save the file to your desktop and name it hello.lua.
- From the top menu of Visual Studio Code, select View > Integrated Terminal.
- On all platforms, if you did not have a folder open, the editor starts out in your home directory. If you did have a folder open, the editor starts out in the folder. Navigate to your desktop with the following command: cd ~/Desktop; the ~/ part of the path is shorthand for home directory:

- Now that the Terminal has the desktop directory open (which is where hello.lua should be saved), you can execute the Lua file with the following command: lua hello.lua. You should see hello, world printed to the Terminal.
The last step invoked the Lua binary from the Terminal of Visual Studio with the hello.lua file as an argument. This, in turn, launched the Lua runtime, which executed the file that was provided as an argument. If the Lua runtime did not launch, you may want to review how to set the runtime up in the Tools for Lua section.
- PHP動態網站程序設計
- The Android Game Developer's Handbook
- Beginning Java Data Structures and Algorithms
- JavaScript:Functional Programming for JavaScript Developers
- Visual Basic 6.0程序設計計算機組裝與維修
- 神經網絡編程實戰:Java語言實現(原書第2版)
- Learning Bayesian Models with R
- Learning Vaadin 7(Second Edition)
- Mastering ROS for Robotics Programming
- 零基礎學C語言程序設計
- HTML+CSS+JavaScript網頁制作:從入門到精通(第4版)
- 計算機組裝與維護(第二版)
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術
- Magento 2 Developer's Guide
- IBM DB2 9.7 Advanced Application Developer Cookbook