jeffswt / cooplfuc

Concise Object-Oriented Programming Library For Users in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

COOPLFUC

Concise Object-Oriented Programming Library For Users in C.

Example

#include <stdio.h>
#include "cooplfuc.h"
#include "vector.h"

class_begin(MyClass)
    int a;
    method(int, foo1, int x);
    method(int, foo2);
    method(int, foo3, int a, int b);
    staticmethod(int, bar, int x, int y);
class_end(MyClass)

method_begin(int, MyClass, foo1, int x)
    return self->a + x;
method_end()

method_begin(int, MyClass, foo2)
    return self->a * 2;
method_end()

method_begin(int, MyClass, foo3, int a, int b)
    return self->a * a * b;
method_end()

staticmethod_begin(int, MyClass, bar, int x, int y)
    return x * y;
staticmethod_end()

initmethod_begin(MyClass, int a)
    self->a = a;
    loadmethod(MyClass, foo1);
    loadmethod(MyClass, foo2);
    loadmethod(MyClass, foo3);
    loadmethod(MyClass, bar);
initmethod_end()

int main(int argc, char** argv)
{
    defvar(MyClass, mc, 5);
    printf("%d\n", apply(mc, foo1, 10));
    printf("%d\n", apply(mc, foo2));
    printf("%d\n", apply(mc, foo3, 15, 20));
    printf("%d\n", mc->bar(7, 17));
    return 0;
}

About

Concise Object-Oriented Programming Library For Users in C

License:MIT License


Languages

Language:C 100.0%