lua-users home
lua-l archive

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


Lua doesn't do any (from what I've tested) optimizations on compilation stage. Even 2 literal string won't be concated being nearby, dead code elimination as well.
On 30 Jul 2021, 10:16 +0300, 重归混沌 <findstrx@gmail.com>, wrote:

Lua5.4 introduces the 'const' keyword, that's great. But when I test some cases, I have a question.

I test the code as follow:

```lua

local a<const> = 1

if a == 1 then
        print("hello world")
else
        print("foobar")

end

```

Because the variable 'a' is always be 1.  So I think `if a == 1` should be removed during the compilation stage.

The equivalent code after compilation should be as follows:

```Lua

        print("hello world")

```

But Luac didn't do it.

 I'm curious why Lua didn't do it.

Thanks for your answer.