The trick is that the console PATHEXT mechanism understands "double extensions", i.e. adding a .exe.lua
"extension" to PATHEXT
will make executable only those Lua scripts which have their full-name ending in .exe.lua
(of course you can choose another extension, say .run.lua
). Note: I used the quotes to avoid possible confusion and for lack of better terminology (remember that, conventionally, the file extension is the part of the file name after the last dot).
Therefore by adding .exe.lua
to PATHEXT
only whatevername.exe.lua
will be executable, whereas any other Lua script won't (provided it doesn't have the same "double extension").
This allows to distinguish "normal" scripts from "executable" ones without either separating them in different directories or define a new custom file extension, which involves modification to the registry.
Moreover since this behaviour is controlled by an environment variable, it is a per-process setting - you can enable it only for a specific console window. For example if you create a batch file with this content:
@set PATHEXT=%PATHEXT%;.exe.lua &cmd /K
and you run it, it will open a console that will be able to execute all .exe.lua
scripts found on the path, but not any other .lua
script.