I mean the situation when lua is run not as embedded in another app but as standalone scripting language.
I need something like PHP_BINARY
or sys.executable
in python. Is that possible with LUA ?
1 Answer. For finding the full path of the Python interpreter you can use sys. executable which contains the full path of the currently running Python interpreter.
First, press Start in the lower-left corner then press Search followed by all files and folders. Type python.exe in the top text line that shows up and then press the search. A folder name will be listed where Python got installed. Hence the folder name becomes the path of Python.
Note that the the solution given by lhf is not the most general. If the interpreter has been called with additional command line parameters (if this may be your case) you will have to search arg
.
In general the interpreter name is stored at the most negative integer index defined for arg
. See this test script:
local i_min = 0
while arg[ i_min ] do i_min = i_min - 1 end
i_min = i_min + 1 -- so that i_min is the lowest int index for which arg is not nil
for i = i_min, #arg do
print( string.format( "arg[%d] = %s", i, arg[ i ] ) )
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With