Jump to content

Luau (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gluonz (talk | contribs) at 00:03, 4 August 2024 (Adding comma to clarify that Lua itself is not developed but Roblox Corporation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Luau
Logo
FamilyLua (programming language)
DeveloperRoblox Corporation
First appeared27 August 2019
Implementation languageC++, Lua
PlatformRoblox Studio
OSWindows, MacOS
LicenseMIT License
File formats.rbxm
Websitehttps://luau-lang.org

Luau is a dialect of the programming language Lua, developed by Roblox Corporation for use in Roblox Studio to create games on Roblox. A derivative of Lua 5.1, Luau supports gradual typing and is designed to maximize performance.[1][2][3][4]

Examples

Instances refers to objects in the game and some of them can be parented and some have a "child".

Part spawns in constant code

Here's an example code for spawning a "Part" (Roblox Block instance, shown here as "brick") every 10 second. Spawning in the position 0, 0, 0. "game" refers to the game itself. "Workspace" is where the player can interact, a 3D environment. "CFrame" is used as the position of "brick".

while wait(10) do
    local brick = instance.new("Part")
    brick.parent = game.Workspace
    brick.position = CFrame.new(0, 0, 0)
end

Note that "Workspace" is a child of "game". This script is a "Script" instance and it's placed in "ServerScriptService", a parent of "game".

Function codes

Another example is to use custom functions and instance's "Signal". If the instance has triggered a change, the signal will be fired. In this example, instance "Button" has a "ClickDetector" which fires the signal "MouseClick" whenever "Button" is pressed. "Connect(<Name Of The Function To Run>) is to run the function in the parenthesis whenever the Signal is fired. This time we are going to run a custom function called "onClicked()" and it will change "Button's" colour and material.

Button = script.parent

function onClicked()
button.BrickColor = BrickColor.new("Medium Stone Grey")
button.Material = Enum.Material.DiamondPlate
end

Button.ClickDetector.MouseClick:Connect(onClicked)

Adding comments

See the code block below to see the example of comments.

--See here for the use of comments 

--This is an example comment
--[[This is an example of Multi-line comment
hello world,
This is a Wikipedia edit.]]


  1. ^ "Why Luau?". Luau. Retrieved 3 August 2024. All of these motivated us to start reshaping Lua 5.1 that we started from into a new, derivative language that we call Luau. Our focus is on making the language more performant and feature-rich, and make it easier to write robust code through a combination of linting and type checking using a gradual type system.
  2. ^ "Compatibility". Luau. Retrieved 3 August 2024. Luau is based on Lua 5.1, and as such incorporates all features of 5.1, except for ones that had to be taken out due to sandboxing limitations.
  3. ^ Shepherd, Harry (13 August 2018). "The best Roblox games". PCGamesN. Archived from the original on 29 November 2018. Retrieved 29 November 2018.
  4. ^ Vanbrocklin, Tyler (26 December 2012). "How to Learn Roblox and Roblox Studio". Game Development Envato Tuts+. Retrieved 7 June 2020.