luaL_tolstring and type coersion #339
-
Is it intended that luaL_tolstring converts numbers in the stack to strings (when not using LuauSchubfach algorithm)? Since the function pushes a new value on the stack I would expect it to not modify the existing stack item. In more general terms what is the plan for type coersion in Luau? Later Lua versions have been gradually removing type coersions from the language, as it is nowadays seen as a mistake. Especially the Lua API should be clean of type coersions in my opinion as they often cause subtle bugs (lua_tostring etc.). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Not really intentional, should be fixed once Schubfach gets enabled - we noticed this during this cleanup. The number coercion was definitely a mistake. The issue is that it's pretty prevalent, and the compatibility implications aren't fully understood. For example, removing coercion from the API will also remove it from builtin libraries and any host-provided FFI - which seems like a good thing but also may break compatibility. I think Lua 5.4 started making steps towards removing it but our behavior is likely consistent with previous Lua versions atm. Something I've considered is a separate configuration option to outright prohibit all of these conversions, although that is likely not something we can enable by default. Broadly, we'll need to investigate the compatibility implications for removing any given conversion (e.g. we know that coercing numbers to strings during string concatenation is essential since some code relies on this broadly, but is coercing strings to numbers during arithmetics as essential? We'll need data on this). |
Beta Was this translation helpful? Give feedback.
Not really intentional, should be fixed once Schubfach gets enabled - we noticed this during this cleanup.
The number coercion was definitely a mistake. The issue is that it's pretty prevalent, and the compatibility implications aren't fully understood. For example, removing coercion from the API will also remove it from builtin libraries and any host-provided FFI - which seems like a good thing but also may break compatibility. I think Lua 5.4 started making steps towards removing it but our behavior is likely consistent with previous Lua versions atm.
Something I've considered is a separate configuration optio…