有没有办法获取正在运行当前脚本的解释器的路径和名称? [英] is there a way to get path and name of the interpreter that is running current script?
问题描述
我的意思是当lua不是以嵌入在另一个应用程序中而是以独立的脚本语言运行时的情况.
I mean the situation when lua is run not as embedded in another app but as standalone scripting language.
我需要python中的PHP_BINARY
或sys.executable
之类的东西. LUA有可能吗?
I need something like PHP_BINARY
or sys.executable
in python. Is that possible with LUA ?
推荐答案
请注意,lhf给出的解决方案不是最通用的.如果已使用其他命令行参数调用了解释器(如果您遇到这种情况),则必须搜索arg
.
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
.
通常,解释器名称存储在为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
这篇关于有没有办法获取正在运行当前脚本的解释器的路径和名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!