Volt

LuaStateProxy:Execute

Schedules code execution on this Lua state.

Syntax

state:Execute(source: string, ...: any) -> ()

Parameters

ParameterTypeDescription
sourcestringThe Lua code to execute
...anyArguments passed to the script

Returns

This method does not return a value.

Description

LuaStateProxy:Execute schedules code execution on the Lua state. The code string will be executed in the context of that state, and any additional arguments will be passed to the script via varargs (...).

Example

local state = getluastate()

state:Execute([[
    print("Executed on state:", ...)
]], "arg1", "arg2")

Execute on Actor State

local actor = Instance.new("Actor")
actor.Parent = workspace

local actorState = getluastate(actor)
actorState:Execute([[
    print("Running on actor state!")
    print("Arguments:", ...)
]], "test", 123)

Pass Data to State

local gameState = getgamestate()

local data = {
    message = "Hello",
    value = 42
}

gameState:Execute([[
    local data = ...
    print("Message:", data.message)
    print("Value:", data.value)
]], data)

Setup Code on New States

on_actor_state_created.Event:Connect(function(actor)
    local state = getluastate(actor)
    
    state:Execute([[
        -- Setup code runs before any scripts
        print("State initialized!")
        _G.setupComplete = true
    ]])
end)

Notes

  • Code executes asynchronously on the target state
  • Arguments are passed via varargs (...)
  • Useful for injecting code or setting up state before scripts run

On this page