haxe C++ externs with template and enum

265 views Asked by At

I have been trying to figure out how to create haxe externs for c++ libraries, and have been trying to get some classes from themispp working, but I'm a bit confused.

I linked a haxelib dev directory to the themis src directory, to make adding it to the @:buildXml easier, that part and @:includes seem to be working ok, but I'm having trouble setting up externs that reference c++ enums and templates, so I'm wondering what is the best way to go about it.

This is the file I'm trying to create externs for: themis/secure_keygen.hpp

Keypair generation interface: themis wiki

enum asym_algs{EC, RSA};

template <asym_algs alg_t_p>
class themispp::secure_key_pair_generator_t {
     void gen();
     const std::vector<uint8_t>& get_priv();
     const std::vector<uint8_t>& get_pub();  
};

This is my current progress:

 @:buildXml("
<files id='haxe'>
  <compilerflag value='-I${haxelib:themis}/src/wrappers/themis/themispp/'/>
    <compilerflag value='-I${haxelib:themis}/src/soter/'/>
    <compilerflag value='-I${haxelib:themis}/src/themis/'/>
</files>
<files id='__lib__'>
  <compilerflag value='-I${haxelib:themis}/src/wrappers/themis/themispp/'/>
    <compilerflag value='-I${haxelib:themis}/src/soter/'/>
    <compilerflag value='-I${haxelib:themis}/src/themis/'/>
</files>
")

@:include("soter_error.h")
@:include("themis_error.h")
@:include("themis.h")
@:include("secure_keygen.hpp")
@:include("secure_rand.hpp")

@:native("themispp::secure_key_pair_generator_t")
extern class SecureKeyPairGeneratorEC
{
    @:native("themispp::secure_key_pair_generator_t<themispp::EC>")
    public static function create():SecureKeyPairGeneratorEC;
}

Main.hx

class Main
{
    static function main()
    {
        SecureKeyPairGeneratorEC.create();
    }
}

attempted to compile with:

-cpp bin/win -cp src -dce no -lib themis -main Main

error:

Error: Main.cpp
./src/Main.cpp(33): error C2653: 'themispp': is not a class or namespace name
./src/Main.cpp(33): error C2065: 'secure_key_pair_generator_t': undeclared identifier
./src/Main.cpp(33): error C2065: 'EC': undeclared identifier
./src/Main.cpp(33): error C2059: syntax error: ')'
Error: Build failed

Generated Main.cpp

0

There are 0 answers