getscriptclosure
Gets the main function of a script.
Syntax
getscriptclosure(script: LocalScript | ModuleScript | Script) -> function | stringParameters
| Parameter | Type | Description |
|---|---|---|
script | LocalScript, ModuleScript, or client Script | The script |
Returns
| Type | Description |
|---|---|
function | A newly compiled closure on success |
string | A compilation error message |
Description
getscriptclosure compiles a new closure from a script's bytecode. It is not the closure currently running in the game, and for a ModuleScript it is not the value returned by require().
Example
local scripts = getrunningscripts()
if #scripts > 0 then
local closure = getscriptclosure(scripts[1])
print("Got closure:", closure)
local constants = debug.getconstants(closure)
print("Constants:", #constants)
endAccessing Module Functions
local modules = getloadedmodules()
for _, module in ipairs(modules) do
local closure = getscriptclosure(module)
local protos = debug.getprotos(closure)
print(module.Name, "has", #protos, "inner functions")
endIf the bytecode cannot be read, the function raises an error. A string result indicates that compilation failed.
Related Functions
getscriptbytecode- Get bytecodegetsenv- Get script environment
Aliases
getscriptfunction