arma-rs
The best way to make Arma 3 Extensions.
Usage
[]
= "1.10.0"
[]
= "my_extension"
= ["cdylib"]
Hello World
use ;
"my_extension" callExtension ["hello", []]; // Returns ["Hello", 0, 0]
"my_extension" callExtension ["welcome", ["John"]]; // Returns ["Welcome John", 0, 0]
Command Groups
Commands can be grouped together, making your large projects much easier to manage.
use ;
Commands groups are called by using the format group:command. You can nest groups as much as you want.
"my_extension" callExtension ["hello:english", []]; // Returns ["Hello", 0, 0]
"my_extension" callExtension ["hello:english:casual", []]; // Returns ["Hey", 0, 0]
"my_extension" callExtension ["hello:french", []]; // Returns ["Bonjour", 0, 0]
Callbacks
Extension callbacks can be invoked anywhere in the extension by adding a variable of type Context to the start of a handler.
use Context;
Call Context
Since Arma v2.11 additional context is provided each time the extension is called. This context can be accessed through the optional Context argument.
use Context;
Support for this context can be can be toggled using the call-context feature flag, which is enabled by default.
Persistent State
Both the extension and command groups allow for type based persistent state values with at most one instance per type. These state values can then be accessed through the optional Context argument.
Global State
Extension state is accessible from any command handler.
use ;
use ;
Group State
Command group state is only accessible from command handlers within the same group.
use ;
use ;
Custom Return Types
If you're bringing your existing Rust library with your own types, you can easily define how they are converted to Arma.
Error Codes
By default arma-rs will only allow commands via RvExtensionArgs. Using callExtension with only a function name will return an empty string.
"my_extension" callExtension "hello:english" // returns ""
"my_extension" callExtension ["hello:english", []] // returns ["Hello", 0, 0]
This behvaiour can be changed by calling .allow_no_args() when building the extension. It is recommended not to use this, and to implement error handling instead.
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Command not found |
| 2x | Invalid argument count, x is received count |
| 3x | Invalid argument type, x is argument position |
| 4 | Attempted to write a value larger than the buffer |
| 9 | Application error, from using a Result |
Error Examples
"my_extension" callExtension ["add", [1, 2]]; // Returns ["3", 0, 0]
"my_extension" callExtension ["sub", [1, 2]]; // Returns ["", 1, 0]
"my_extension" callExtension ["add", [1, 2, 3]]; // Returns ["", 23, 0], didn't expect 3 elements
"my_extension" callExtension ["add", [1, "two"]]; // Returns ["", 31, 0], unable to parse the second argument
"my_extension" callExtension ["overflow", []]; // Returns ["", 4, 0], the return size was larger than the buffer
"my_extension" callExtension ["should_error", [true]]; // Returns ["told to error", 9, 0]
"my_extension" callExtension ["should_error", [false]]; // Returns ["told to succeed", 0, 0]
Testing
Tests can be created utilizing the extension.call() method.
Unit Loadout Array
arma-rs includes a loadout module to assist with the handling of Arma's Unit Loadout Array.
let l = r#"[[],[],[],["U_Marshal",[]],[],[],"H_Cap_headphones","G_Aviator",[],["ItemMap","ItemGPS","","ItemCompass","ItemWatch",""]]"#;
let mut loadout = from_arma.unwrap;
loadout.set_secondary;
loadout.set_primary;
let uniform = loadout.uniform_mut;
uniform.set_class;
let uniform_items = uniform.items_mut.unwrap;
uniform_items.push;
uniform_items.push;
Common Rust Libraries
arma-rs supports some common Rust libraries. You can enable their support by adding their name to the features of arma-rs.
= { = "1.8.0", = ["chrono"] }
Please create an issue first if you would like to add support for a new library.
chrono
chrono - Convert to Arma
NaiveDateTime and DateTime<TimeZone> will be converted to Arma's date array.
The timezone will always be converted to UTC.
chrono - Convert From Arma
Arma's date array can be converted to NaiveDateTime.
uuid
uuid - Convert To Arma
Uuid will be converted to a string.
serde_json
serde_json - Convert To Arma
Any variant of serde_json::Value will be converted to the appropriate Arma type.
Building for x86 (32 Bit)
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.