lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Float to integer conversions, especially the ones involving table keys, are considered harmful by a lot of the people who replied to my __key feature request. So instead I'd like to request -DLUA_NOCONVF2I. It should make those people happier, as it removes the closest analog to __key we currently have in the VM.

-DLUA_NOCONVF2I would apply to anything that requests an integer, all bitwise operators, and indexing operations. It should lead to a faster Lua VM and more robust code, as well as a lot more runtime errors.

-DLUA_NOCONVF2I would make t[1.0] and t[1] refer to different keys:

local t = {}
t[1.0] = "a"
t[1] = "b"
print(t[1.0], t[1]) --> a b

As well as produce an error in the following cases:

("str"):sub(1.0, -1.0)
1 << 1.0
1.0 | 0

-----------------------------

Integer to float conversions are the ones that happen when you mix integers and floats in expressions. Thisshould also lead to a faster Lua VM and more robust code, as well as a lot more runtime errors.

-DLUA_NOCONVI2F would make all of the following produce an error:

1.0 + 2 (mixed integer/float operations)
anything involving integers and the following operators: /, ^

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.