Admin Mod plugins are written in the language Small. The official documentation is available as a PDF File. However, you should note that Admin Mod doesn't use the latest version of Small yet, and a few parts of the Small standard library are not available. Please refer to the reference section of this guide for a definitive list of native functions rather than the small language manual.
Below is a brief synopsis of the language for those familiar with programming. Comparisons are given for C and Visual Basic.
Small only has one - 32 bit integer, also known as a cell. It also supports fixed length arrays of 32 bit integers.
Strings are represented by putting the ASCII code of each character in a cell of an array, so each character of a string takes 4 bytes or memory in Small.
Booleans are represented by storing 1 for True or 0 for False in a 32 bit integer. The conditional statements treat any non-zero value as True.
Multi-dimensional arrays are supported as global or local variables. However, due to a compiler bug, you are not able to pass them as an argument to a function. You can pass single dimensional arrays as arguments.
In Small, variables are declared with the "new" keyword. This does not have the same meaning as the new keyword in C or Visual basic - its more like the Dim keyword in VB or the var keyword in Java Script. Small uses new to declare local or module level variables - it does not dynamically allocate memory and there is no delete keyword or any garbage collection.
| C | Visual Basic | Small |
|---|---|---|
| int x; | Dim x As Long | new x; |
| int x=0; | Dim x As Long x = 0 |
new x = 0; |
| int x[10]; | Dim x(10) As Long | new x[10]; |
| char str[10]; | Dim str As String | new str[10]; |
| char str[] = "hello"; | Dim str As String str = "hello" |
new str[]="hello"; |
| x = malloc(10); | Set X = New Something | N/A |
Small has no dynamic memory management. All global variables (those defined outside functions) are allocated a space in the actual AMX file at compile time. Local variables (those defined inside functions) are allocated in a stack while executing the function. The stack takes a default size of 2048 cells (8K), although if you are running low you can override this with a #pragma dynamic - e.g. To set it to 10000 cells:
#pragma dynamic 10000
Small does support the static declaration for local variables in the same way as C and VB. A static local variable behaves like a global variable, but your cannot see it outside the function. I have never seen an Admin Mod plugin bother to use one!
Small functions are declared in a similar way to C functions except there is no need to declare a return type - it is always a 32 bit integer as that is the only data type supported.
Integer arguments can be passed by value or by reference. If passed by value, changing the value inside the function won't affect it outside. Arrays are always passed by reference.
| C | Visual Basic | Small |
|---|---|---|
| int func() { return 0; } |
Function func() func =0 End Function |
func() { return 0; } |
| void func() { } |
Sub func() End Sub |
func() { } |
| void func(int x, int &y) { } |
Sub func(ByVal x, ByRef y) End Sub |
func(x,&y) { } |
| int func(char* str) { } |
Function func(ByRef str As String) End Function |
func(str[]) { } |
| N/A | Function func(ByVal str As String) End Function |
N/A |
| void func(int x, ...) { } |
Sub func(ByVal x, ParamArray As Variant) End Sub |
func(x,...) { } |
Functions can be declared public. This means that Admin Mod is allowed to call them. Any function that is an Admin Mod event handler, a registered command handler or a timer/ vote/ menu handler must be declared as public. e.g.
public plugin_init() {
}
Small supports the standard constructs for program flow - if, while, for and switch. Note that Small requires additional braces around each case statement if it contains multiple statements, and it is not necessary to use break at the end of each case.
| C | Visual Basic | Small |
|---|---|---|
| if (x>0) { y=1; } else { y=2; } |
If x>0 Then y=1 Else y=2 End If |
if (x>0) { y=1; } else { y=2; } |
| if (x>0) { y=1; } else if (x<0) { y=2; } else { y=3; } |
If x>0 Then y=1 ElseIf x<0 Then y=2 Else y=3 End If |
if (x>0) { y=1; } else if (x<0) { y=2; } else { y=3; } |
| while (x>0) { x--; } |
While x>0 x=x-1 End While |
while (x>0) { x--; } |
| do { x--; } while (x>0); |
Do x=x-1 While x>0 |
do { x--; } while (x>0); |
| for (x=1;x<=10;x++) { } |
For x=1 To 10 Next x |
for (x=1;x<=10;x++) { } |
| switch (x) { case 0,1: y=1; break; case 2,3: y=2; break;default: y=0; } |
Select x Case 0,1 y=1 Case 2,3: y=2 Default y=0 End Select |
switch (x) { case 0,1: { y=1; } case 2,3: { y=2; } default: { y=0; } } |
Small supports #define for creating numeric constants and #include in the same way as C. However, it does not support string constants - you have to use global variables.
| C | Visual Basic | Small |
|---|---|---|
| #include <file> | N/A | #include <file> |
| #include "file" | N/A | #include "file" |
| #define NAME 10 | Const NAME As Long = 10 | #define NAME 10 |
| #define NAME "string" | Const NAME As String = "string" | N/A |
You will find references to the following in the Small manual. None of them are applicable to Admin Mod plugins:
We also recommend that you ignore the library of standard functions supplied in the official language documentation - the reference section of this site shows all native functions implemented by Admin Mod.