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
ipairs
loadstring
Returns
Variant
Code Samples
Loadstring
-- LoadStringEnabled must be turned on in ServerScriptService
local compiled, errorMessage = loadstring("return 1 + 2")
if compiled then
print(compiled()) --> 3
else
print("Failed to load:", errorMessage)
end
-- Invalid code returns nil followed by an error message
local broken, syntaxError = loadstring("return +")
print(broken, syntaxError) --> nil <the syntax error>newproxy
next
pairs
pcall
rawequal
rawget
rawset
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
tonumber
unpack
Properties
_G
Code Samples
Sharing Values With _G
-- Script A stores a value in _G
_G.mySharedValue = "hello from Script A"
-- Script B, running at the same context level, can read it
print(_G.mySharedValue) --> hello from Script A
-- Any function can read and update shared state, too
_G.counter = (_G.counter or 0) + 1
print(_G.counter) --> 1