Lua Programming environment has to be setup before you start compiling and executing all the available examples online. It helps you in verifying the programs with different options.
Try below example using our online compiler available at CodingGround
For most of the examples given in this tutorial, there will be a Try it option in our website code sections on the top right corner. This will take you to the online compiler, so just make use of it to enjoy learning.
To set up Lua programming language environment, software’s such as (a) Text Editor, (b) The Lua Interpreter and (c) Lua Compiler should be available on your computer.
To write a program in Lua, a text editor is needed to type a program. Examples of a few editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
Name and version of the text editor vary based on different operating systems. For example, Notepad will be used on Windows and vim or vi can be used on Windows as well as Linux or UNIX.
Files created with the editor are called source files and these files contain program source code. Source files of Lua programs are characteristically named with the extension ".lua".
It is a small program which allows in typing Lua commands and executes them immediately. It will stop the execution of a Lua file if it encounters an error contrast to a compiler which executes fully.
When Lua is extended to other languages/applications, a Software Development Kit with a compiler is required which is compatible with Lua Application Program Interface.
Separate IDE named "SciTE" has been developed for windows environment which can be downloaded from https://code.google.com/p/luaforwindows/ download section.
Run the downloaded executable to install Lua IDE.
As it is an IDE, you can create and build Lua code using the same.
If you are like installing Lua in command line mode, you should install MinGW or Cygwin and then compile and install Lua in windows.
To download and build Lua, use below command
To install Lua on other platforms like aix, ansi, bsd, generic linux, mingw, posix, solaris by replacing Linux in make Linux, test with corresponding platform name.
We have a helloWorld.lua, in Lua as follows
Now, we can build and run a Lua file say helloWorld.lua by switching to the folder containing the file using cd and then using below command
We can see below output.
To build/test Lua in Mac OS X, use below command
In few cases, Xcode and command line tools may not be installed on your system and due to this, you will not be able to use the make command. Install Xcode from mac app store. Then go to Preferences of Xcode and then switch to Downloads and install the component named "Command Line Tools". After completing the process, make command will be available for you to use.
It is not mandatory to execute "make macosx test" statement but even without executing this command, you will still be able to use Lua in Mac OS X.
We have a helloWorld.lua, in Lua, as follows
Now, you can build and run a Lua file say helloWorld.lua by switching to the folder containing the file using cd and then using below command
We can see below output
For Windows SciTE, Lua IDE is the default IDE provided by Lua creator team. Alternate IDE available is from ZeroBrane Studio which is available across multiple platforms like Windows, Mac and Linux.
There are also plugins for eclipse which enable Lua development. By using IDE, development becomes easy with features like code completion and is highly suggested. IDE also provides interactive mode programming similar to the command line version of Lua.
Lua (programming language) Related Interview Questions
|Python Interview Questions||HTML 5 Interview Questions|
|ASP.NET Interview Questions||Oracle 11g Interview Questions|
|C & Data Structures Interview Questions||Basic Programming Interview Questions|
|Six Sigma Interview Questions||SQL Interview Questions|
|Java Abstraction Interview Questions||Data Structure & Algorithms Interview Questions|
|Computer Programming Interview Questions||PMP Interview Questions|
|.Net Deployment Interview Questions|
Lua (programming Language) Tutorial
Lua (programming Language)
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.