This document explains the custom "class system" in C, using specific syntax patterns designed to mimic object-oriented programming (OOP) features like classes, methods, and object creation in C. These syntax patterns are processed by a preprocessor in your pipeline.
Supported Formats
Static Method Call on a Class
- Description: Calls a static method belonging to the class itself rather than an instance.
- Example:
MyClass::initialize(config);
Calls the static method initialize
of MyClass
, passing config
as an argument.
Object Creation
Class class = new Class(params);
- Description: Creates a new instance of a class.
- Example:
MyClass obj = new MyClass("example");
Creates an object obj
of type MyClass
with the parameter "example"
passed to its constructor.
Calling a Method on an Instance
- Description: Calls a non-static method on an instance of a class.
- Example: Calls
doSomething
on obj
, passing 10
as an argument.
Conditional Method Call with Type Casting
if (class::(bool)condition(params));
- Description: Calls a method conditionally based on a boolean value returned by
condition
.
- Example:
if (obj::isValid(config)) {
obj::processData(data);
}
If isValid(config)
is true, it calls processData(data)
.
Calling a Method on a Child Object
(class->child)::Method(params);
- Description: Calls a method on a child object of a class.
- Example:
(obj->child)::updateChildInfo(info);
Calls updateChildInfo
on child
, a member of obj
.
Key Concepts in the Class System
- Static Methods: Belong to the class itself, callable with
ClassName::Method()
.
- Object Creation:
new Class(params)
creates objects similar to OOP languages.
- Instance Methods: Belong to an instance, callable with
instance::Method()
.
- Conditional Calls: Calls methods based on conditions, optionally with type casting.
- Child Objects: Calls methods on child objects with
class->child::Method()
.
This custom syntax mimics object-oriented behavior in C, allowing it to follow OOP-like patterns while remaining procedural.