Repository navigation
objects.h
tanazd1 edited this page Apr 5, 2026
·
3 revisions
objects.h defines a macro-based system that enables structured object-like constructs in C.
- Provide object-style abstraction
- Remain compatible with standard C
- Avoid dynamic allocation
An Object is a statically allocated structure containing:
- Identifier (name)
- Line storage
- Key-value storage
- Execution function
A Line is a null-terminated string stored in a fixed buffer.
A KV Pair is a mapping:
string → string
A function pointer attached to an object, executed via runtime macros.
typedef struct ObjKV {
char key[64];
char value[256];
} ObjKV;typedef struct Obj {
char name[50];
char lines[MAX_OBJ_LINES][MAX_LINE_LEN];
int line_count;
ObjKV kvs[MAX_OBJ_KV];
int kv_count;
void (*run)(struct Obj*, int argc, char** argv);
} Obj;- Objects are statically allocated
- No heap allocation
- Exists for entire program duration
- Maximum: 1024
- Max length: 256 chars
- Maximum: 128
obj(name) {
statements
}Obj obj_<name>;
- name set to string
- counters initialized to zero
- run pointer set to NULL
for (Obj* _obj_ptr = &obj_<name>; _obj_ptr; _obj_ptr = NULL)- Executes exactly once
- Provides scoped pointer
_obj_ptr
line("text");- Copies string into
lines[] - Increments
line_count
- Must not exceed buffer size
- Silent truncation possible
kvs("key", "value");- Stores key-value pair
- Increments
kv_count
string → string only
cmd(function);- Assigns function pointer
void function(Obj* obj, int argc, char** argv);objadd(name) {
statements
}- Reopens object
- Appends data
objrune(name, "arg1", "arg2");- Constructs argument array
- Computes argc
- Calls run function
objrunve(name, argv);- Passes argv directly
- Sets argc = 0
- argc is not computed
objrunvp → objrunve
objrunvpe → objrunve
objrunpe → objrunve
o->lines[i]o->kvs[i].key
o->kvs[i].valuefor (...) {
if (strcmp(...) == 0)
}- No runtime error reporting
- Silent failures possible
- Limited protection via strncpy
- No explicit null termination guarantee
- Not thread-safe
- Fixed-size buffers
- No dynamic allocation
- No type safety
- Strings only
- No scheduler
- No async execution
- All features implemented via macros
- No runtime parsing
- Fully compatible with standard C compilers
obj(test) {
line("Hello");
kvs("key", "value");
}Object = Static Struct + Macro DSL + Function Pointer
- Typed KV system
- Dynamic allocation
- Object inheritance
- Runtime loader
🧩 Objects Tool • Built for Termux • Zero dependencies
Home • Objects Tool • objects.h • Examples • install.sh
- Macro-based object system for C
- Static memory (no malloc)
- Designed for Termux environment
🚧 Active Development