-
Notifications
You must be signed in to change notification settings - Fork 0
Plugins
A3DB supports three ways to extend its functionality, from simple SQF functions to full native C/Rust plugins.
Register an SQF function callable from SQL as fn_<name>():
// Register
["register_function", ["my_func", 2]] call a3db_fnc_execute;
// Use in SQL
_result = ["SELECT fn_my_func('a', 'b') FROM t"] call a3db_fnc_execute;SQF functions are tracked by name only — the actual evaluation is handled by your SQF code before calling fn_execute.sqf.
For built-in extensions compiled into the DLL:
use a3db::engine::plugin::{PluginFunction, register_plugin};
register_plugin(
"my_plugin",
vec![PluginFunction {
name: "hello".into(),
min_args: 1,
max_args: 1,
func: |args| {
let name = args[0].to_string();
Ok(DbValue::String(format!("Hello, {}!", name)))
},
}],
vec![],
);Registered at startup via init_builtin_plugins() in engine/plugin.rs.
Callable from SQL: SELECT fn_hello('World') FROM t → "Hello, World!"
Shared libraries (.so / .dll) placed in the plugin directory are loaded at runtime.
// my_plugin.c
#include "a3db_plugin.h"
A3DB_PLUGIN_INIT {
a3db_plugin_register_function("my_plugin", "echo", 1, 1);
return "my_plugin";
}gcc -shared -o my_plugin.so my_plugin.c -fPICDrop the compiled .so/.dll into a directory and load from SQF:
["plugin_dir @a3db/plugins"] call a3db_fnc_execute;Or load via TCP:
plugin_dir /path/to/plugins
_result = ["plugins"] call a3db_fnc_execute;
// → [0, "OK", [["builtin_echo", ["echo"], []], ["sqf_user", ["my_func"], ["sqf_called"]]]]
// plugin_name functions hooksSee include/a3db_plugin.h in the repository for the full header.
| Function | Purpose |
|---|---|
a3db_plugin_init() |
Required. Entry point, called at load. Returns plugin name. |
a3db_plugin_register_function(name, fn_name, min_args, max_args) |
Register a SQL function (callable as fn_<name>) |
A complete example plugin is at plugins/example/plugin.c in the repository.
C ABI plugins have full access to the game process. Only load plugins from trusted sources.