Engine Global
Luau globals
Summary
Functions
collectgarbage(operation: string):Variant |
getmetatable(t: Variant):Variant |
loadstring(contents: string,chunkname: string):Variant |
require(module: ModuleScript | string | number):Variant |
setmetatable(t: table,newMeta: Variant):table |
API Reference
Functions
assert
collectgarbage
error
getfenv
getmetatable
getmetatable(t:Variant):Variant
Parameters
t:Variant |
Returns
Variant
Code Samples
Getmetatable
local meta = {}
local t = setmetatable({}, meta)
print(getmetatable(t) == meta) --> true
-- Make the original metatable unrecoverable by setting the __metatable metamethod:
meta.__metatable = "protected"
print(getmetatable(t)) --> protectedipairs
loadstring
newproxy
next
pairs
pcall
Returns
Code Samples
Pcall
local function divideByFive(n: number): number
return n / 5
end
local success, errorMessage = pcall(divideByFive, "notANumber") -- Results in error...
if success then
-- Handle successful response...
else
print("Error message:", errorMessage)
endrawset
require
Parameters
Returns
Variant
Code Samples
Require Module Resolution
-- "./" prefix is equivalent to script.Parent
require("./MySibling")
require((script.Parent).MySibling)
-- "../" prefix is equivalent to script.Parent.Parent
require("../SiblingOfMyParent")
require((script.Parent.Parent).SiblingOfMyParent)
-- "../" can be chained to go up multiple levels
require("../../SiblingOfMyGrandparent")
require((script.Parent.Parent).Parent.SiblingOfMyGrandparent)
-- "@self" prefix corresponds to the script itself
require("@self/MyChild")
require((script).MyChild)
-- "@game" prefix corresponds to the DataModel root
require("@game/ReplicatedStorage/Shared/MyModule")
require((game).ReplicatedStorage.Shared.MyModule)select
setfenv
setmetatable
Parameters
newMeta:Variant |
Returns
Code Samples
Setmetatable
local meta = {__metatable = "protected"}
local t = {}
setmetatable(t, meta) -- This sets the metatable of t
-- We now have a table, t, with a metatable. If we try to change it...
local ok, err = pcall(setmetatable, t, {})
assert(not ok and err:find("protected")) -- Error: cannot change a protected metatabletonumber
Parameters
arg:Variant |
| Default Value: 10 |
Returns
Variant
Code Samples
Tonumber
print(tonumber("1337")) --> 1337 (assumes base 10, decimal)
print(tonumber("1.25")) --> 1.25 (base 10 may have decimal portions)
print(tonumber("3e2")) --> 300 (base 10 may have exponent portion, 3 × 10 ^ 2)
print(tonumber("25", 8)) --> 21 (base 8, octal)
print(tonumber("0x100")) --> 256 (assumes base 16, hexadecimal)
print(tonumber("roblox")) --> nil (does not raise an error)
-- Tip: use with assert if you would like unconvertable numbers to raise an error
local ok, err = pcall(function() assert(tonumber("roblox")) end)
print(ok and "Success" or "Error: " .. tostring(err)) --> Error: assertion failedtostring
unpack
Properties