Top 1,000 Features Creators Resources Extensions Blog Explorer Download
GitHub icon

Lua

< >

Lua is an open source programming language created in 1993 by Roberto Ierusalimschy.

#23on PLDB 31Years Old 244kRepos

Try now: Riju ยท TIO ยท Replit

Lua ( LOO-ษ™, from Portuguese: lua [หˆlu.(w)ษ] meaning moon) is a lightweight, multi-paradigm programming language designed primarily for embedded systems and clients. Lua is cross-platform, since the interpreter is written in ANSI C, and has a relatively simple C API. Lua was originally designed in 1993 as a language for extending software applications to meet the increasing demand for customization at the time. Read more on Wikipedia...


Example from Riju:
print("Hello, world!")
Example from hello-world:
print("Hello World")
# Hello World in Lua print "Hello world"
Example from Linguist:
-- A simple counting object that increments an internal counter whenever it receives a bang at its first inlet, or changes to whatever number it receives at its second inlet. local HelloCounter = pd.Class:new():register("h-counter") function HelloCounter:initialize(sel, atoms) self.inlets = 2 self.outlets = 1 self.num = 0 return true end function HelloCounter:in_1_bang() self:outlet(1, "float", {self.num}) self.num = self.num + 1 end function HelloCounter:in_2_float(f) self.num = f end
Example from Wikipedia:
$ cc -o example example.c -llua $ ./example Result: 8
and break do else elseif end false for function goto if in local nil not or repeat return then true until while

Language features

Feature Supported Token Example
Constants โœ“
pi  = 3.14159
Lists โœ“
myList = {1, 2, 3}
Bitwise Operators โœ“
& | ~ << >> ~
Hexadecimals โœ“
-- 0[xX][0-9a-fA-F]+ (integer)
-- 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+([pP][+-]?[0-9]+)? (float)
0x5F3759DF
0x0.1D
0xA23p-4
0X1.921FB54442D18P+1
Integers โœ“
80766866
Floats โœ“
-- [0-9]*\.[0-9]+([eE][+-]?[0-9]+)? -- (decimal float)
-- 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+([pP][+-]?[0-9]+)? -- (hex float)
Scientific Notation โœ“
1E2
.12345E+6
1.e+0
0x15e-2
0x2.p10
0X.8p-0
0x1.Fp+0
0x1fffp-16
0x1p-2
Conditionals โœ“
if true then
    print("true")
end
Functions โœ“
function myFunction()
    print("hello")
end
While Loops โœ“
while true do
    print("hello")
end
Booleans โœ“ true false
true
false
Strings โœ“ "
"Hello world"
Print() Debugging โœ“ print
print("hello world")
Maps โœ“
myMap = {
    key = "value",
    [35] = 35,
}
Line Comments โœ“ --
-- A comment
Operator Overloading โœ“
Assignment โœ“
MultiLine Comments โœ“ --[[ --]]
--[[
A comment.
--]]
Comments โœ“
Case Insensitive Identifiers X
Semantic Indentation X
Octals X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Published by Breck's Lab