Created
October 21, 2015 00:16
-
-
Save uliwitness/a7a19a4450ffe6938b39 to your computer and use it in GitHub Desktop.
Wrapping C++ in Swift via a C wrapper.
This file contains 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 "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(); | |
} |
This file contains 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
#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 */ |
This file contains 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
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