Skip to content

Instantly share code, notes, and snippets.

@bartlomiejn
Created March 26, 2017 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartlomiejn/8ffa67d40dd54bc9324999e348ebf0a3 to your computer and use it in GitHub Desktop.
Save bartlomiejn/8ffa67d40dd54bc9324999e348ebf0a3 to your computer and use it in GitHub Desktop.
C++ class with C bridge definition file for swift-explorations.ghost.io
class CppClass {
public:
CppClass(const char* value) {
storedValue = value;
}
const char* storedValue;
};
extern "C" void* makeObject(const char* storedValue) {
return (void*) new CppClass(storedValue);
}
extern "C" void setNewStoredValue(void* object, const char* newValue) {
auto castedObject = static_cast<CppClass*>(object);
castedObject->storedValue = newValue;
}
extern "C" const char* getStoredValue(void* object) {
auto castedObject = static_cast<CppClass*>(object);
return castedObject->storedValue;
}
extern "C" void removeObject(void* object) {
delete static_cast<CppClass*>(object);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment