API Reference › Builtin functions › arg
function

arg

arg(i) -> string

Returns the command-line argument at index i as a string. Index 0 is conventionally the program's own name or path, so the first user-supplied argument is at index 1. Use it together with arg_count to write configurable command-line tools in Ludic — reading an input filename, a mode flag, or a numeric option. Guard the index against arg_count() before reading so you never ask for an argument that was not passed.

Parameters

ithe argument index (0 is the program name)

Example

program EchoFirstArg {
  handler ShowArg phase Start {
    if arg_count() > 1 {
      print(arg(1))
    } else {
      print("no argument")
    }
  }
}
← All symbols