summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-03-30 15:23:45 +1100
committerdaurnimator <quae@daurnimator.com>2018-03-30 15:29:59 +1100
commit955c73898c992ef15396bafdf4383ce8a9bf1843 (patch)
treeef605da9f7f946bf35f7397d2dbadded219cb45f
parente1ac6d64eb82550f3b935ac7d0e81bd1a201cd8e (diff)
downloadfengari-955c73898c992ef15396bafdf4383ce8a9bf1843.tar.gz
fengari-955c73898c992ef15396bafdf4383ce8a9bf1843.tar.bz2
fengari-955c73898c992ef15396bafdf4383ce8a9bf1843.zip
Add 'fengari' library containing version numbers etc
-rw-r--r--src/fengarilib.js42
-rw-r--r--src/linit.js4
-rw-r--r--src/lualib.js4
3 files changed, 50 insertions, 0 deletions
diff --git a/src/fengarilib.js b/src/fengarilib.js
new file mode 100644
index 0000000..158fb03
--- /dev/null
+++ b/src/fengarilib.js
@@ -0,0 +1,42 @@
+const {
+ lua_pushinteger,
+ lua_pushliteral,
+ lua_setfield
+} = require('./lua.js');
+const {
+ luaL_newlib
+} = require('./lauxlib.js');
+const {
+ FENGARI_AUTHORS,
+ FENGARI_COPYRIGHT,
+ FENGARI_RELEASE,
+ FENGARI_VERSION,
+ FENGARI_VERSION_MAJOR,
+ FENGARI_VERSION_MINOR,
+ FENGARI_VERSION_NUM,
+ FENGARI_VERSION_RELEASE,
+ to_luastring
+} = require("./fengaricore.js");
+
+const luaopen_fengari = function(L) {
+ luaL_newlib(L, {});
+ lua_pushliteral(L, FENGARI_AUTHORS);
+ lua_setfield(L, -2, to_luastring("AUTHORS"));
+ lua_pushliteral(L, FENGARI_COPYRIGHT);
+ lua_setfield(L, -2, to_luastring("COPYRIGHT"));
+ lua_pushliteral(L, FENGARI_RELEASE);
+ lua_setfield(L, -2, to_luastring("RELEASE"));
+ lua_pushliteral(L, FENGARI_VERSION);
+ lua_setfield(L, -2, to_luastring("VERSION"));
+ lua_pushliteral(L, FENGARI_VERSION_MAJOR);
+ lua_setfield(L, -2, to_luastring("VERSION_MAJOR"));
+ lua_pushliteral(L, FENGARI_VERSION_MINOR);
+ lua_setfield(L, -2, to_luastring("VERSION_MINOR"));
+ lua_pushinteger(L, FENGARI_VERSION_NUM);
+ lua_setfield(L, -2, to_luastring("VERSION_NUM"));
+ lua_pushliteral(L, FENGARI_VERSION_RELEASE);
+ lua_setfield(L, -2, to_luastring("VERSION_RELEASE"));
+ return 1;
+};
+
+module.exports.luaopen_fengari = luaopen_fengari;
diff --git a/src/linit.js b/src/linit.js
index a265045..8f461a4 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -38,3 +38,7 @@ loadedlibs[lualib.LUA_UTF8LIBNAME] = luaopen_utf8;
loadedlibs[lualib.LUA_DBLIBNAME] = luaopen_debug;
if (typeof process !== "undefined")
loadedlibs[lualib.LUA_IOLIBNAME] = require('./liolib.js').luaopen_io;
+
+/* Extension: fengari library */
+const { luaopen_fengari } = require('./fengarilib.js');
+loadedlibs[lualib.LUA_FENGARILIBNAME] = luaopen_fengari;
diff --git a/src/lualib.js b/src/lualib.js
index 78f441f..d5f8d9d 100644
--- a/src/lualib.js
+++ b/src/lualib.js
@@ -52,5 +52,9 @@ const LUA_LOADLIBNAME = "package";
module.exports.LUA_LOADLIBNAME = LUA_LOADLIBNAME;
module.exports.luaopen_package = require("./loadlib.js").luaopen_package;
+const LUA_FENGARILIBNAME = "fengari";
+module.exports.LUA_FENGARILIBNAME = LUA_FENGARILIBNAME;
+module.exports.luaopen_fengari = require("./fengarilib.js").luaopen_fengari;
+
const linit = require('./linit.js');
module.exports.luaL_openlibs = linit.luaL_openlibs;