Yuescript icon indicating copy to clipboard operation
Yuescript copied to clipboard

`moonp` does not pass command line arguments.

Open daelvn opened this issue 4 years ago • 1 comments

In lua, you can have a script such as:

for k, v in pairs {...} do print k, v end
-- or --
for k, v in pairs arg do print k, v end

Which then you can run as lua test.lua a b c to get:

1 a
2 b
3 c

But, doing this with moonp -e test.mp a b c:

for k, v in pairs {...} do print k, v
-- or --
for k, v in pairs arg do print k, v

Gives you either of these errors:

1: cannot use '...' outside a vararg function near '...'
for k, v in pairs {...} do print k, v
# or #
test.mp:1: bad argument #1 to 'for iterator' (table expected, got nil)

Does moonp not pass CLI arguments at all?

daelvn avatar Jan 10 '21 04:01 daelvn

Yes, moonp was not passing CLI arguments. But found the real issue was a wrong syntax check in compiler. It should be fixed by the newest commit.

# These use cases are available for moonp now
moonp -e "print k, v for k, v in pairs {...}" a b c
moonp -e test.mp a b c

pigpigyyy avatar Jan 11 '21 02:01 pigpigyyy