Command Line Arguments in AngelScript

Command-line arguments are a common way to parameterize execution of programs. For example, angelscript script.as arg1 arg2 uses arg1 and arg2 as arguments to the script.

void main()
{
    // Get access to command-line arguments
    array<string> args = GetCommandLineArgs();

    // The first argument is the script name
    array<string> argsWithProg = args;
    array<string> argsWithoutProg = args.slice(1);

    // You can get individual args with normal indexing
    string arg = args[3];

    print(argsWithProg);
    print(argsWithoutProg);
    print(arg);
}

To experiment with command-line arguments, you’ll need to run the script with the AngelScript interpreter and provide arguments:

$ angelscript command-line-arguments.as a b c d
["command-line-arguments.as", "a", "b", "c", "d"]
["a", "b", "c", "d"]
c

Note that in AngelScript, there’s no built-in way to access command-line arguments directly. The GetCommandLineArgs() function used in this example is hypothetical and would need to be implemented as part of the hosting application or as an extension to the AngelScript standard library.

Also, AngelScript doesn’t have a concept of building standalone executables. It’s typically embedded in a host application or run through an interpreter.

Next, we’ll look at more advanced command-line processing techniques specific to AngelScript or its host application.