Initial commit
This commit is contained in:
commit
f222bb92af
9 changed files with 359 additions and 0 deletions
55
example/main.c
Normal file
55
example/main.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <mini-obj-c.h>
|
||||
|
||||
#include "MObject.h"
|
||||
|
||||
static struct Object* static_method(struct Object* self);
|
||||
static struct Object* instance_method(struct Object* self);
|
||||
|
||||
int main()
|
||||
{
|
||||
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),
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue