getscriptclosure
Gets the main function of a script.
Syntax
getscriptclosure(script: LocalScript | ModuleScript) -> functionParameters
| Parameter | Type | Description |
|---|---|---|
script | LocalScript or ModuleScript | The script |
Returns
| Type | Description |
|---|---|
function | The script's main function |
Description
getscriptclosure returns the main function (closure) of a script. For ModuleScripts, this is the function that would be returned by require().
Example
local scripts = getrunningscripts()
if #scripts > 0 then
local closure = getscriptclosure(scripts[1])
print("Got closure:", closure)
-- Inspect the function
local constants = debug.getconstants(closure)
print("Constants:", #constants)
endAccessing Module Functions
local modules = getloadedmodules()
for _, module in ipairs(modules) do
local closure = getscriptclosure(module)
-- Get module's protos (inner functions)
local protos = debug.getprotos(closure)
print(module.Name, "has", #protos, "inner functions")
endRelated Functions
getscriptbytecode- Get bytecodegetsenv- Get script environment
Aliases
getscriptfunction