diff --git a/hbjs.js b/hbjs.js index 5d07a38..d414af6 100644 --- a/hbjs.js +++ b/hbjs.js @@ -533,7 +533,23 @@ function hbjs(Module) { return trace; } - function get_version() { + function version() { + var major = exports.malloc(4); + var minor = exports.malloc(4); + var patch = exports.malloc(4); + exports.hb_version(major, minor, patch); + var version = [ + heapu32[major / 4], + heapu32[minor / 4], + heapu32[patch / 4] + ]; + exports.free(major); + exports.free(minor); + exports.free(patch); + return version; + } + + function version_string() { var versionPtr = exports.hb_version_string(); var version = utf8Decoder.decode(heapu8.subarray(versionPtr, heapu8.indexOf(0, versionPtr))); return version; @@ -546,7 +562,8 @@ function hbjs(Module) { createBuffer: createBuffer, shape: shape, shapeWithTrace: shapeWithTrace, - version: get_version(), + version: version, + version_string: version_string, }; } diff --git a/test/index.js b/test/index.js index 7a52dd6..464d0b2 100644 --- a/test/index.js +++ b/test/index.js @@ -249,8 +249,16 @@ describe('shape', function () { }); describe('misc', function () { + it('get version', function () { + const version = hb.version(); + expect(version).to.be.an('array'); + expect(version).to.have.lengthOf(3); + expect(version[0]).is.a('number'); + expect(version[1]).is.a('number'); + expect(version[2]).is.a('number'); + }); it('get version string', function () { - const version = hb.version - expect(version).to.match(/^\d+\.\d+\.\d+$/); + const version_string = hb.version_string(); + expect(version_string).to.match(/^\d+\.\d+\.\d+$/); }); });