genepi icon indicating copy to clipboard operation
genepi copied to clipboard

feature idea: GENEPI_ENUM

Open m59peacemaker opened this issue 4 years ago • 0 comments

Unless an issue is discovered, it seems valid to represent a c++ enum in JS as Object<string, number>. This may accord well with genepi's higher level abstraction over node-addon-api.

I have created a macro for this purpose, which could be used like:

enum Color { red, green, blue };
GENEPI_ENUM(Color, red, green, blue);
NAMED_GENEPI_ENUM(Color, COOLER, red, green, blue);
const { Color, COOLER } = require(binding)
Color.blue // => 2
COOLER.blue // => 2

I am sharing this here in case it is of interest as a future feature of genepi.

m59peacemaker avatar Aug 20 '21 16:08 m59peacemaker