Skip to content

Instantly share code, notes, and snippets.

@agrif
Last active December 20, 2015 10:49
Show Gist options
  • Select an option

  • Save agrif/6118953 to your computer and use it in GitHub Desktop.

Select an option

Save agrif/6118953 to your computer and use it in GitHub Desktop.
#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
};
#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__ */
#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