girvel / fallen

Tactical adventure made with LOVE2D
1 stars 0 forks source link

Statics can mess up shared metatables #411

Open girvel opened 1 month ago

girvel commented 1 month ago

static overwriting __serializes generated by other statics is a feature, allowing for cascade static tables. But overwriting __serialize in general can cause issues. For example, Vectors shouldn't be marked as statics ever, because they have a shared metatable. One Vector marked as static and all vectors when serialized will return the same vector. So, metatables that should be shared should repel static and cause an error when marked with it. I will definitely forget about marking some shared metatable as repelling and create a headache-causing bug, so probably all metatables not containing __allow_static should repel static by default. Maybe if there is a wide demand for marking metatabled objects with static we can do static.unsafe sugar, but I highly doubt that we'll need that.

girvel commented 1 month ago

But sometimes I actually need to make something with a shared metatable static. For example, the sound of the action surge. Maybe there is a point to remove if not mt.serialize completely, then static's serialize; it would look like Dump.serializers[t] and it would not mess with metatables at all. Static also changes __newindex by force, so it should be changed only if the table does not have a metatable yet.

girvel commented 1 month ago

Work is saved at static-rework