Add JS_VERSION_MAJOR/MINOR/PATCH defines to mujs.h

A macro JS_CHECKVERSION(major, minor, patch) can be used to test the
version if your code depends on API features added in a given version.

#if JS_CHECKVERSION(1, 2, 0)
    ... use new API ...
#else
    ... don't use new API ...
#endif
This commit is contained in:
Tor Andersson
2021-10-21 14:04:52 +02:00
parent 1780d0ea73
commit dd0a0972b4
2 changed files with 9 additions and 0 deletions

2
main.c
View File

@@ -356,6 +356,8 @@ main(int argc, char **argv)
}
if (interactive) {
printf("Welcome to MuJS %d.%d.%d.\n",
JS_VERSION_MAJOR, JS_VERSION_MINOR, JS_VERSION_PATCH);
if (isatty(0)) {
using_history();
rl_bind_key('\t', rl_insert);

7
mujs.h
View File

@@ -7,6 +7,13 @@
extern "C" {
#endif
#define JS_VERSION_MAJOR 1
#define JS_VERSION_MINOR 2
#define JS_VERSION_PATCH 0
#define JS_VERSION (JS_VERSION_MAJOR * 10000 + JS_VERSION_MINOR * 100 + JS_VERSION_PATCH)
#define JS_CHECKVERSION(x,y,z) (JS_VERSION >= ((x) * 10000 + (y) * 100 + (z)))
/* noreturn is a GCC extension */
#ifdef __GNUC__
#define JS_NORETURN __attribute__((noreturn))