Skip to content

Instantly share code, notes, and snippets.

@uliwitness
Created October 21, 2015 00:16
Show Gist options
  • Save uliwitness/a7a19a4450ffe6938b39 to your computer and use it in GitHub Desktop.
Save uliwitness/a7a19a4450ffe6938b39 to your computer and use it in GitHub Desktop.
Wrapping C++ in Swift via a C wrapper.
#include "cppwrapper.h"
#include "buff.hpp"
extern "C" void buff_deinit( buff* _this )
{
delete _this;
}
extern "C" buff* buff_init( int type, double amount, double max_amount, double start_angle, double relative_angle, double max_distance, double bleedthrough, bool permanent )
{
return new buff(type,amount,max_amount,start_angle,relative_angle,max_distance,bleedthrough,permanent);
}
extern "C" int buff_get_type( buff* _this )
{
return _this->get_type();
}
#if __cplusplus
extern "C"
{
#endif /* __cplusplus */
typedef struct buff buff;
void buff_deinit( buff* _this );
buff* buff_init( int type, double amount, double max_amount, double start_angle, double relative_angle, double max_distance, double bleedthrough, bool permanent );
int buff_get_type( buff* _this );
#if __cplusplus
}
#endif /* __cplusplus */
public class buff
{
let cppinstance : COpaquePointer
deinit {
buff_deinit(cppinstance)
}
public init(type : Int32,amount : Double,max_amount : Double,start_angle : Double,relative_angle : Double,max_distance : Double,bleedthrough : Double,permanent : Bool) {
cppinstance = buff_init(type,amount,max_amount,start_angle,relative_angle,max_distance,bleedthrough,permanent)
}
public func get_type() -> Int32 {
return buff_get_type(cppinstance)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment