Pawn (scripting language)

Pawn, formerly known as Small, is an open source scripting language primarily intended as an embeddable scripting language. It is maintained by a Dutch company named CompuPhase, which released the first version in 1998. The language was known as Small until version 3 was released in March 2005.

Pawn is a dynamically typed language influenced by Small-C. and has C-like syntax

Pawn is used in the San Andreas Multiplayer mod, Half-Life mod, AMX Mod X and Source Engine based SourceMod as well as various other projects.

Design

Pawn is a compiled language. Its regular extension is '.p' or '.pwn'.

The Pawn compiler compiles to P-code (or bytecode) that will be written to a file with a '.amx' extension.

Features

  • Pawn is a C-like Scripting Language
  • You can include files in Pawn; so you can arrange a neat structure of Pawn code
  • Pawn is a scripting language with a compiler that performs static checks, and an abstract machine with (static) P-code verification and dynamic checks.
  • For porting purposes, Pawn is written in ANSI C as much as possible; Endian issues are handled.
  • Pawn supports Unicode/UCS-4 and UTF-8, as well as codepages. The compiler can convert source code entered in a particular codepage to Unicode; it also supports source code files in UTF-8 format.
  • It has been fitted on an Atmel ATmega128 microcontroller, Philips LPC2138 and LPC2106 microcontrollers (ARM7TDMI core with 32 kiB RAM), as well as on a Texas Instrument's MSP430F1611 (MSP430 core with 10 kiB RAM and 48 kiB Flash ROM). Using code overlays that are loaded on demand, pawn is able to run large scripts in little memory.
  • Documenting the source code can be done with "documentation comments;" the pawn compiler extracts those comments, combines them with information it deduces from the source code and writes an XML file that is immediately viewable (and printable) with a web browser.
  • Pawn supports states and automatons in the language, including state-local variables.

Uses

Grand Theft Auto: San Andreas Multiplayer

A common use for Pawn is in the popular unofficial Grand Theft Auto: San Andreas modification "San Andreas Multiplayer". This allows server hosts to enable their scripts to perform all the tasks available to players of the single player version of "Grand Theft Auto: San Andreas". This is made possible by the ability for server hosts to create their own "game modes" with the PAWN compiler. The implementation of the PAWN language also allows users to interact with the game in ways previously not possible in the single player environment.

Counter-Strike

Pawn also allows scripters to create various plugins for Half-life mods, such as Counter-Strike.

Side-script design

PAWN is designed to be used as a side-script with code from other languages. PAWN does not ship with native functions which can be used for developing, instead Pawn's functions come from "include" files.

Code Examples

Here is an example of code that will print 4 random digits.

#include <core>
main() {
    new digit[4];//Introduces a new variable with an individual digit size of 4.
    for(new i=0;i<4;i++)//Will loop 4 times to fill the var 'digit.'
    {
        digit[i] = random(5000);//Gives the digit a random number in between 0 and 5000.
        printf("Digit %d's value is %d.", i, digit[i]);//Prints the digit and the digit's value on screen.
    }
    return 1;//Returns the number 1.
}

Here is a 'Hello World!' example.

#include <core>
main() {
    print("Hello World!");
}

See also

  • SMALL

References

cs:Pawn es:Pawn fr:Pawn (langage de programmation) it:Pawn (linguaggio) he:Pawn (שפת תכנות) ka:Pawn nl:Pawn pl:PAWN pt:Pawn ru:Pawn sr:Pawn sv:Pawn tr:PAWN