debug.setlocal
Example
Prints the local variables, sets them, then prints the variables again.
local var1 = "Luke, I am not your father."
local var2 = "PMFPMF"
(function()
print("Getting the locals now!")
PrintTable({debug.getlocal(2, 1)})
PrintTable({debug.getlocal(2, 2)})
print("\nSetting the locals now!")
print(debug.setlocal(2, 1, "I'm actually your mother."))
print(debug.setlocal(2, 2, "Chemo-chi"))
print(debug.setlocal(2, 3, "nil should be returned here!"))
print("\nHere are the locals after being set!")
PrintTable({debug.getlocal(2, 1)})
PrintTable({debug.getlocal(2, 2)})
end)()
Output:
Getting the locals now!
1 = var1
2 = Luke, I am not your father.
1 = var2
2 = PMFPMF
Setting the locals now!
var1
var2
nil
Here are the locals after being set!
1 = var1
2 = I'm actually your mother.
1 = var2
2 = Chemo-chi