#include #include #include "MObject.h" static struct Object* static_method(struct Object* self); static struct Object* instance_method(struct Object* self); struct Method Test_meta_methods[] = { { .sel = "staticMethod", .impl = static_method }, }; struct Class TestMetaClass = { .class = &TestMetaClass, .name = "Test(meta)", .super = &MObjectMetaClass, .methods = Test_meta_methods, .methods_count = sizeof(Test_meta_methods) / sizeof(struct Method), }; struct Method Test_methods[] = { { .sel = "instanceMethod", .impl = instance_method }, }; struct Class Test = { .class = &TestMetaClass, .name = "Test", .super = &MObject, .methods = Test_methods, .methods_count = sizeof(Test_methods) / sizeof(struct Method), }; int main() { msg_send((struct Object*)&Test, "staticMethod"); struct Object* obj = msg_send((struct Object*)&Test, "alloc"); msg_send(obj, "instanceMethod"); msg_send(obj, "release"); } static struct Object* static_method(struct Object* self) { struct Class* class = (struct Class*)self; printf("Hello from class '%s'\n", class->name); return self; } static struct Object* instance_method(struct Object* self) { printf("Hello from instance of '%s'\n", self->class->name); return self; }