Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to get path and name of the interpreter that is running current script?

Tags:

lua

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 ?

like image 598
rsk82 Avatar asked Aug 16 '13 09:08

rsk82


People also ask

How do you find the interpreter path?

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.

How do I get Python interpreter path?

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.


1 Answers

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
like image 128
Lorenzo Donati -- Codidact.com Avatar answered Oct 06 '22 00:10

Lorenzo Donati -- Codidact.com