samyeyo / LuaRT-Studio

Lua 5.4 IDE for Windows with debugger and script to executable compiler
Other
71 stars 11 forks source link

`arg[]` start at index 2 when using CMD paramaters in studio #23

Closed Dismalitie closed 5 months ago

Dismalitie commented 5 months ago

When using command line arguments in Studio, it is set as the 2nd index instead of the first. The first index returns the filepath that the script is running from. This is annoying since the whole point of the command line params feature is to help you test, but instead you have to make a sort of offset. It works normally when running from a separate command prompt:

start echo.exe "hello!"
> hello!

I don't know if this is a debug feature but it just triggers me I guess.

print(arg[2]) -- prints the first arg
print(arg[1]) -- prints the filepath

Thanks for reading anyways! 👍

samyeyo commented 5 months ago

It's not LuaRT Studio related.

When running a LuaRT script, here is what the arg table contains :

When running from a compiled script, here is what the arg table contains :

In standard Lua, the arg table contains :

Dismalitie commented 5 months ago

Oh, I didn't even know that arg existed in PUC-Lua!

samyeyo commented 5 months ago

In fact, there is no recommendation for the arg table, because it is created by the Lua interpreter and not the Lua runtime library. For the next version of LuaRT, I will provide an implementation for the arg table closer to that of PUC Lua, for interpreted and compiled script (there won't be any differences anymore)