zc is a single header library for C which adds some nice QOL features, such as:
Integer list myList = many(Integer, 10) vs int* myList = malloc(sizeof(int) * 10))To get started, do this:
git clone https://chookspace.com/max/zc
cd zc
sudo make install
Read the docs below to know how to use
Create an entry point for your program
entry {
}
From here, do stuff like this:
entry {
print("Hello, World!");
}
Variables are defined in a similar way to C.
Integer x; // defines x with no value
x is 5; // gives x a value
print(x);
String y is "dingus"; // assign with a value
print(y)
Integer list z is many(Integer, 10); // Creates a list with space for 10 integers
for (Integer a is 0; a < 10; a increment) z[a] is a * 10; // Give them all a value
Due to the nature of the C preprocessor which this project makes heavy use of, defining classes works differently in zc to other programming languages.
Create a class:
class(Car, {
String make;
Integer year;
Method(Car, drive, void, Integer fuel); // usage: Method(className, methodName, returnType, args...)
Destructor(Car);
});
Define it's methods:
method(Car, drive, void, Integer fuel) {
printf("A %s can drive %d km with %d fuel", self->make, fuel * 5, fuel); // Use self to access the other fields in the class
}
destructor(Car) {
free(self->make);
}
Finally, make a constructor:
constructor(Car, String make, Integer year) {
return (Car) {
.make is make,
.year is year,
.drive is __Car_drive, // format for methods is __ClassName_methodName
.destructor_fn is destroyCar // format for destructor is destroyClassName
};
}
Use your newly made class:
entry {
Car myCar = newCar("Toyota", 1996);
myCar.drive(&myCar, 32);
// Don't forget to forget when you're done!
// If you don't have a destructor, this call won't compile.
forget(myCar);
}