[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Question about 'const' variable
- From: 重归混沌 <findstrx@...>
- Date: Wed, 11 Aug 2021 11:28:17 +0800
I am more curious, why does Lua not optimize 1==1.
Both the f and the g are being optimized in those examples. Note how
the f function uses the LOADK instruction instead of GETUPVAL.
The `local a <const> = 1` in your original program is also optimized,
transforming the `a == 1` into `1 == 1`. However, Lua doesn't optimize
the `1 == 1` as you would expect. That's a separate problem that is
unrelated to the constant variables.