unused code removal

28 views
Skip to first unread message

eugeny gladkih

unread,
Nov 11, 2025, 12:04:56 PM (yesterday) Nov 11
to lu...@googlegroups.com
re,

will the compiler remove unused a local variable and a string in the code like that?

local function get_locations()
local PXY_ETC_DIR<const> = '/opt/pxy/etc’
local PXY_HOME_ROOT<const> = '/opt/pxy’
local PXY_RUN_DIR<const> = '/run’
local PXY_VAR_ROOT<const> = '/var/opt/pxy'

return PXY_HOME_ROOT..'/', PXY_ETC_DIR..'/', PXY_VAR_ROOT..'/'
end

‘PXY_RUN_DIR’ is not used here at all.

--
Yours sincerely, Eugeny.


Андрей Закатов

unread,
Nov 11, 2025, 12:12:07 PM (yesterday) Nov 11
to lu...@googlegroups.com
As far as I'm aware Lua does not optimize anything currently, so you'll still have space allocated for it.

You can also luac -l -l the file to see what the bytecode would look like

--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/1944E298-DE99-481F-B51F-19FED0BD5E99%40drweb.com.

Андрей Закатов

unread,
Nov 11, 2025, 12:20:08 PM (yesterday) Nov 11
to lu...@googlegroups.com
Oh apparently I'm wrong and looking at the output of the luac the /run is indeed removed
Damn...

Bas Groothedde

unread,
Nov 11, 2025, 12:33:17 PM (yesterday) Nov 11
to lu...@googlegroups.com
They are marked const, so they are not variables.

Remove the const and see what happens. 

~b

On 11 Nov 2025, at 18:20, Андрей Закатов <zahat...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages