Format & Strings#
The SDK provides freestanding replacements for common C standard library functions since printf, sprintf, strlen, etc. are not available in WASM plugins.
Format (Format.hpp)#
Number formatting utilities and a stack-allocated string builder.
TextBuilder#
The recommended way to build strings. Stack-allocated, chainable, and safe.
| Method | Returns | Description |
|---|---|---|
put(const char* str) |
TextBuilder& |
Append a string |
putChar(char c) |
TextBuilder& |
Append a single character |
putInt(int value) |
TextBuilder& |
Append an integer (handles negatives) |
putFloat(float value, int decimals = 1) |
TextBuilder& |
Append a float with N decimal places |
c_str() |
const char* |
Get the null-terminated result |
length() |
int |
Current string length |
clear() |
void |
Reset the builder |
// Display distance
TextBuilder<32> buf;
buf.put("Distance: ").putInt(static_cast<int>(enemy.GetDistance())).put("m");
Draw::Text(x, y, Color::White(), buf.c_str());
// Display health
TextBuilder<64> hp;
hp.put("HP: ").putInt(static_cast<int>(enemy.GetHealth()))
.put("/").putInt(static_cast<int>(enemy.GetHealthMax()));
Draw::Text(x, y + 15, Color::Green(), hp.c_str());
// Float formatting
TextBuilder<32> sens;
sens.put("Sens: ").putFloat(GetSensitivity(), 2);
Log(sens.c_str());
Tip
TextBuilder is the replacement for sprintf. Use it anywhere you need to combine text and numbers.
fmt::int_to_str#
Formats a signed integer into buf. Handles negative numbers and INT_MIN. Returns the number of characters written (excluding null terminator), or 0 if the buffer is too small.
fmt::uint_to_str#
Formats an unsigned integer into buf. Returns chars written, or 0 if buffer is too small.
fmt::float_to_str#
Formats a float into buf with the specified number of decimal places. Handles negative values and rounds correctly.
| Parameter | Type | Description |
|---|---|---|
value |
float |
The value to format |
buf |
char* |
Output buffer |
buf_size |
int |
Size of the output buffer |
decimals |
int |
Digits after the decimal point (default: 1) |
String Functions (String.hpp)#
Freestanding implementations of standard C string functions. These are defined at global scope (no namespace) since there is no libc to conflict with.
| Function | Signature | Description |
|---|---|---|
strlen |
size_t strlen(const char* s) |
Returns the length of a null-terminated string |
strcmp |
int strcmp(const char* a, const char* b) |
Compares two strings lexicographically |
strcpy |
char* strcpy(char* dst, const char* src) |
Copies a string including null terminator |
strncpy |
char* strncpy(char* dst, const char* src, size_t n) |
Copies up to n characters, pads with nulls |
strcat |
char* strcat(char* dst, const char* src) |
Appends src to the end of dst |
char name[32];
strcpy(name, "Enemy: ");
strcat(name, GetHeroName(enemy.GetHeroId()));
Draw::Text(x, y, Color::White(), name);
Memory Functions (Memory.hpp)#
Freestanding implementations of standard C memory functions.
| Function | Signature | Description |
|---|---|---|
memcpy |
void* memcpy(void* dst, const void* src, size_t n) |
Copies n bytes from src to dst |
memset |
void* memset(void* dst, int val, size_t n) |
Fills n bytes of dst with val |
memcmp |
int memcmp(const void* a, const void* b, size_t n) |
Compares n bytes, returns 0 if equal |
Include Order#
All three headers are automatically included by SDK.hpp in the correct order:
#include "Memory.hpp" // memcpy, memset, memcmp
#include "String.hpp" // strlen, strcmp, strcpy (depends on Memory.hpp)
#include "Format.hpp" // TextBuilder, fmt::* (depends on String.hpp)
You don't need to include them separately — just use #include <xenon/SDK.hpp>.