Exit in AngelScript

Here’s the translation of the Go code to AngelScript, formatted in Markdown suitable for Hugo:

import std.stdio;
import std.process;

void main()
{
    // defer will not be run when using exit(), so this println will never be called.
    defer { println("!"); }

    // Exit with status 3.
    exit(3);
}

In AngelScript, we can use the exit() function from the std.process module to immediately exit the program with a given status.

Note that unlike some languages, AngelScript does not use an integer return value from main() to indicate exit status. If you’d like to exit with a non-zero status, you should use the exit() function.

To run this script, you would typically save it as a .as file and run it using an AngelScript interpreter or compiler. The exact command may vary depending on your setup, but it might look something like this:

$ angelscript exit.as
exit status 3

If you compile the script into an executable, you can run it directly and check the exit status:

$ ./exit
$ echo $?
3

Note that the ! from our program never got printed. This is because defer statements (or their equivalent in AngelScript) are not executed when using exit().

It’s important to note that the exact behavior and availability of these features may depend on the specific AngelScript implementation and runtime environment you’re using. Some environments may not support certain system-level operations like setting exit codes.

Also, keep in mind that while this example demonstrates how to exit a program with a specific status code, in many AngelScript contexts (such as game scripting), abruptly exiting the script might not be appropriate or even possible. Always consider the specific requirements and constraints of your AngelScript environment.