Lua

From Soyjak Wiki, the free ensoyclopedia
(Redirected from Help:Lua for beginners)
Jump to navigationJump to search
This page is Brappy.Eat unos takis y drink un refresco before you read this page o algo
mw:Lua, index at MediaWiki.
ihfkjfh blox yeeey hahaha
This page is a stub or is unfinished. (You) VVILL help by expanding it.
Literally Lua.

Lua is a lightweight yet high-level programming language made by brapzillian programmer Roberto Ierusalimschy, it's very similar to Python in terms of syntax. Its main purpose is to be embedded in other applications. A fork of Lua, which is Luau, is used as the main scripting language for Roblox.

Its package manager is LuaRocks, it handles the distribution, installation, and management of Lua modules, modules being reusable lines of code.

Lua means "Moon" in Portuguese, hence the logo.

Lua is often embedded into C and C++ programs as a scripting language, and can interact with those C/C++ applications. This is why it is often used as a scripting language in many games. This is because Lua provides its own header <lua.h> (<lua.hpp> for C++GODs) for these purposes.

Unusual aspects

[edit | edit source]
  • In Lua, any value that is not nil or false is considered true.
  • Lua uses indexes beginning with 1, not 0, even though most languages index beginning with 0.
  • Lua doesn't have a continue keyword. Instead, to exit the current iteration of a loop, you need to use goto statements. Some forks of Lua (like Luau) do have a continue keyword by default though.
  • Variables are Global by default. Make sure you specify Local.

Example

[edit | edit source]
-- seed the random number generator with the current time
math.randomseed(os.time())

-- determines whether the tranny should ack based on a probability
-- ackProbability: number between 0 and 100 representing the chance of acking
-- returns true if the random chance is less than ackProbability, false otherwise
local function shouldAck(ackProbability)
    -- generate a random number between 0 and 100
    local prob = math.random() * 100

    -- clamp the probability to ensure it's between 0 and 100
    ackProbability = math.max(0, math.min(ackProbability, 100))

    -- return true if random number is less than ack probability
    return prob < ackProbability
end
 
-- main function that decides whether to ack or print "TRANS RIGHTS ARE HUMAN RIGHTS!!!!"
local function main()
    if shouldAck(41) then
        print("ACK!!!!")
    else
        print("TRANS RIGHTS ARE HUMAN RIGHTS!!!!!!!!")
    end
end

-- run the main function
main()

Modules

[edit | edit source]

Main article: Soyjak Wiki:Module

TL;DR: Modules are programs written in Lua 5.1.x and executed by the Scribunto extension. They can do things such as automatically putting recent happenings and major events on the main page.

Snopes