-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wasm] Generate properties / methods for enums #2391
Comments
Currently we're using Embind
It's not very intuitive to add properties / methods support, so it might be better to use import { TWCoinType } from "<path or package>"
enum CoinType {
bitcoin = 0,
ethereum = 60,
}
// a method to convert CoinType to TWCoinType and call properties / methods |
After some testing, we'd better to generate extra class CoinTypeEnum {
CoinTypeEnum(TWCoinType value)
: value(value)
{}
TWCoinType getValue() const { return value; }
void setValue(TWCoinType value_) { value = value_; }
}
EMSCRIPTEN_BINDINGS(Wasm_TWCoinType_EnumClass) {
class_<CoinTypeEnum>("CoinTypeEnum")
.constructor()
.property()
.function()
;
} |
@MaximPestryakov Here the idea is too create a class additionally to the enum in order to have properties, the codegen tools need to iterate through possible properties and gen as described by @hewigovens above. properties / function are in |
Similar to swift enum extension it's how we should generate the code for wasm enum: header: // Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
//
// This is a GENERATED FILE, changes made here WILL BE LOST.
//
#pragma once
#include "TrustWalletCore/TWCoinType.h"
#include <emscripten/bind.h>
using namespace emscripten;
namespace TW::Wasm {
class WasmCoinTypeExtension {
public:
TWCoinType value;
WasmCoinTypeExtension(TWCoinType value) : value(value) {}
auto blockchain();
// others function to codegen
};
} c++: // Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
//
// This is a GENERATED FILE, changes made here WILL BE LOST.
//
#include "CoinTypeExtension.h"
using namespace emscripten;
namespace TW::Wasm {
auto WasmCoinTypeExtension::blockchain() {
return TWCoinTypeBlockchain(this->value);
}
EMSCRIPTEN_BINDINGS(Wasm_CoinTypeExtension) {
class_<WasmCoinTypeExtension>("CoinTypeExtension")
.constructor<TWCoinType>()
.function("blockchain", &WasmCoinTypeExtension::blockchain);
}
} Swift extensions: https://github.com/trustwallet/wallet-core/blob/master/codegen/lib/templates/swift/enum_extension.erb |
properties in
TWCoinType.h
are not generated right nowThe text was updated successfully, but these errors were encountered: