-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow User to extend enums (#8)
Enum mappers are now a bit different, you declare your enums as usual in C++, but then add the converter functions to the `EnumMapper` namespace: ```cpp namespace margelo { // 1. Create your C++ enum enum Backend { METAL, OPEN_GL, VULKAN }; namespace EnumMapper { // 2. Add JS Union -> C++ Enum converter for your enum specifically static void convertJSUnionToEnum(const std::string& inUnion, Backend* outEnum) { if (inUnion == "metal") *outEnum = METAL; else if (inUnion == "open-gl") *outEnum = OPEN_GL; else if (inUnion == "vulkan") *outEnum = VULKAN; else throw invalidUnion(inUnion); } // 3. Add C++ Enum -> JS Union converter for your enum specifically static void convertEnumToJSUnion(Backend inEnum, std::string* outUnion) { switch (inEnum) { case METAL: *outUnion = "metal"; break; case OPEN_GL: *outUnion = "open-gl"; break; case VULKAN: *outUnion = "vulkan"; break; default: throw invalidEnum(inEnum); } } } // namespace EnumMapper } // namespace margelo ```
- Loading branch information
Showing
3 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
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
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
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