Last active
June 22, 2017 20:35
-
-
Save dvirsky/89466373429a90bfa8a0d727e5bae4f2 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
#ifndef NS_HEADER_NAME_H_ | |
#define NS_HEADER_NAME_H_ | |
/* Enums are defined like data types */ | |
typedef enum { | |
/* Options of enums are documented */ | |
NSEnum_Foo, | |
/* Options of enums are documented */ | |
NSEnum_Bar, | |
} NSEnum; | |
/* NSMyType is a type that belongs to NS. | |
* Multi line comments are in blocks | |
*/ | |
typedef struct NSMyType { | |
// single line comments are allowed, but be consistent | |
NSEnum en; | |
// at least within | |
int numFoos; | |
// the same struct | |
int flag; | |
} NSMyType; | |
/* Constructor of a type */ | |
NSMyType *NS_NewMyType(); | |
/* Struct methods accept a pointer to the struct as the first argument, with a short name */ | |
void NSMyType_Method(NSMyType *mt); | |
// ifdefs are all caps | |
#define NS_SOMETHING_SOMETHING "waat?" | |
/* Interfaces are structs with methods and a context */ | |
typedef struct { | |
void *ctx; | |
/* Interface Methods are CamelCased and do not include the name of the interface */ | |
void (*MethodA)(void *ctx); | |
/* Interface Methods are CamelCased and do not include the name of the interface */ | |
void (*MethodB)(void *ctx, int num); | |
} NSInterface; | |
/* Constructors are declared like so: | |
* (it's okay for interfaces to be passed by value if they are small) | |
*/ | |
NSInterface NS_NewInterface(void *ctx); | |
/* Static methods on interfaces... */ | |
void NSInterface_Free(NSInterface *ni); | |
/* Unexported types/methods in camelCase, just like in Go */ | |
typedef struct { | |
int foo; | |
double bar; | |
} myUnexportedType; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment