CC: Tweaked

CC: Tweaked

57M Downloads

`table.insert` is able to modify read-only tables like `textutils.empty_json_array`

MCJack123 opened this issue ยท 1 comments

commented

Minecraft Version

1.16.x

Version

1.100.5

Details

This issue is more of a notification of a limitation in Cobalt/Lua - no need to get worried about fixing it.

Following Lua 5.1, Cobalt's table.insert function does not respect the __newindex metamethod of tables. This causes an issue when using some global tables like textutils.empty_json_array, as the function bypasses the __newindex metamethod which would normally throw an error, and instead modifies the global table as usual. This can cause some unintended consequences, especially if the user is unaware of these values which are not currently documented properly.

Reproduction is simple:

assert(#textutils.empty_json_array == 0)
assert(not pcall(table.insert, textutils.empty_json_array, 1))
assert(#textutils.empty_json_array == 0)

This test fails on all versions of CC:T since 1.87.0 (when textutils.unserializeJSON was introduced).

The solution is to patch Cobalt to use metamethods, but since the current way is correct with PUC Lua until 5.3, it'll break standards to try to fix it.

commented

which are not currently documented properly.

I'm waiting for your feedback on a question!