Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Multiple assignment ignored by __newindex #6

Open
Ayplow opened this issue Oct 24, 2019 · 1 comment
Open

Multiple assignment ignored by __newindex #6

Ayplow opened this issue Oct 24, 2019 · 1 comment
Labels
bug Something isn't working lua Lua scripting

Comments

@Ayplow
Copy link

Ayplow commented Oct 24, 2019

Describe the bug
Attempting to use multiple assignment on a table with a __newindex metamethod, only the first value will be forwarded to it.

To Reproduce

  1. Add the following script to your scene:
local MT = {}
function MT:__newindex(key, value)
  print(key, " was assigned to [", value, "]")
end
local T = {}
setmetatable(T, MT)
T.A, T.B = 1, 2
  1. Click on 'Save & Play'
  2. This will be output to the Game chat window:
A was assigned to [1]
B was assigned to [nil]

Expected behavior
In the official Lua interpreter, this code outputs

B        was assigned to [      2       ]
A        was assigned to [      1       ]

Tabletop Simulator Info

  • Version 12.1.6

Additional context
Upstream issue: moonsharp-devs/moonsharp#236

@Ayplow
Copy link
Author

Ayplow commented Oct 24, 2019

As this is a fundamental issue with the interpreter, there isn't any direct way to solve the problem as a modder. Until it is fixed, I would recommend never using multiple assignment with table elements

This is a somewhat extreme solution, but if we consider our scripts to be written in 'TTS Lua', then it is the natural consequence of that language not supporting this feature, and ensures that the scripts will be 'forward-'compatible with normal lua

@Ayplow Ayplow added lua Lua scripting bug Something isn't working labels Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working lua Lua scripting
Projects
None yet
Development

No branches or pull requests

1 participant