diff --git a/chookspace/index.html b/chookspace/index.html new file mode 100644 index 0000000..7e592e0 --- /dev/null +++ b/chookspace/index.html @@ -0,0 +1,80 @@ + + + + + + zc + + +

zc - what if C, but easier

+

NOTE: I don't recommend using this in production. Here be dragons!

+

zc is a single header library for C which adds some nice QOL features, such as:

+ +

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

+

Docs

+

Create an entry point for your program

+
entry {
+
+}
+

From here, do stuff like this:

+
entry {
+    print("Hello, World!");
+}
+

Variables

+

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
+

Classes

+

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);
+}
+ + +