Last active
December 20, 2015 10:49
-
-
Save agrif/6118953 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "co-string.h" | |
| #include <stdio.h> | |
| static void co_string_construct(void* p) | |
| { | |
| printf("string construct\n"); | |
| CoString* self = p; | |
| self->data = NULL; | |
| self->length = 0; | |
| } | |
| static void co_string_deconstruct(void* p) | |
| { | |
| printf("string deconstruct\n"); | |
| CoString* self = p; | |
| if (self->data) | |
| free(self->data); | |
| } | |
| co_implementation_define(CoString, CoNew) | |
| { | |
| sizeof(CoString), | |
| co_string_construct, | |
| co_string_deconstruct, | |
| }; | |
| co_type_define(CoString) | |
| { | |
| co_type_implements(CoString, CoNew), | |
| co_type_end | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "cobalt.h" | |
| #ifndef __CO_STRING_H_INCLUDED__ | |
| #define __CO_STRING_H_INCLUDED__ | |
| typedef struct | |
| { | |
| char* data; | |
| size_t length; | |
| } CoString; | |
| co_type_export(CoString); | |
| co_implementation_export(CoString, CoNew); | |
| #endif /* __CO_STRING_H_INCLUDED__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "cobalt.h" | |
| #include "co-string.h" | |
| co_implementation_define(int, CoNew) | |
| { | |
| sizeof(int), | |
| NULL, | |
| NULL, | |
| }; | |
| co_type_define(int) | |
| { | |
| co_type_implements(int, CoNew), | |
| co_type_end | |
| }; | |
| int main(int argc, char** argv) | |
| { | |
| CoString* str = co_new(CoString); | |
| co_delete(str); | |
| int* aint = co_newa(int); | |
| *aint = 0; | |
| return *aint; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment