Volt

getscriptclosure

Gets the main function of a script.

Syntax

getscriptclosure(script: LocalScript | ModuleScript) -> function

Parameters

ParameterTypeDescription
scriptLocalScript or ModuleScriptThe script

Returns

TypeDescription
functionThe 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)
end

Accessing 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")
end

Aliases

  • getscriptfunction

On this page