fileinsert
fileinsert

Reputation: 430

Find name and location of Lua executeable

I need to find the name of the Lua executeable from within a Lua script as it sets up a task for later execution.

Using arg I can find out the name, however this becomes un reliable if options are used. For example, if no arguments are used running within a script print( arg[-1]) would print lua53. However if options are used they would be printed instead, such as -i, and to get the exe I would have change the line to print( arg[-2]).

What method will reliably get the name of the lua binary?

Upvotes: 1

Views: 168

Answers (1)

lhf
lhf

Reputation: 72362

Try this

i=0
repeat i=i-1 until arg[i]==nil
i=i+1
print(i,arg[i])

Upvotes: 3

Related Questions