tts-community / tts-community-bug-tracker

Community maintained list of Tabletop Simulator bugs.
2 stars 0 forks source link

Multiple assignment ignored by __newindex #6

Open Ayplow opened 5 years ago

Ayplow commented 5 years ago

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
  2. Click on 'Save & Play'
  3. 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

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

Ayplow commented 5 years ago

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