summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-22 16:44:00 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-23 16:38:45 +1100
commit78a0d95e74eb3c4c2a4f383fe7aebe6ec8b1652a (patch)
treec0301b2e8224d292706bfc88d6e92cbd2bc54c27 /src
parentd28bfe3d7e489f036ac3b336ecfd7b5d1bf7b0c9 (diff)
downloadfengari-78a0d95e74eb3c4c2a4f383fe7aebe6ec8b1652a.tar.gz
fengari-78a0d95e74eb3c4c2a4f383fe7aebe6ec8b1652a.tar.bz2
fengari-78a0d95e74eb3c4c2a4f383fe7aebe6ec8b1652a.zip
Workaround linit/lualib cyclic reference
Diffstat (limited to 'src')
-rw-r--r--src/linit.js50
-rw-r--r--src/lualib.js11
2 files changed, 30 insertions, 31 deletions
diff --git a/src/linit.js b/src/linit.js
index f717767..a265045 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -2,39 +2,39 @@
const { lua_pop } = require('./lua.js');
const { luaL_requiref } = require('./lauxlib.js');
-const lualib = require('./lualib.js');
const { to_luastring } = require("./fengaricore.js");
-const lbaselib = require('./lbaselib.js');
-const lcorolib = require('./lcorolib.js');
-const lmathlib = require('./lmathlib.js');
-const lstrlib = require('./lstrlib.js');
-const ltablib = require('./ltablib.js');
-const lutf8lib = require('./lutf8lib.js');
-const ldblib = require('./ldblib.js');
-const loslib = require('./loslib.js');
-const loadlib = require('./loadlib.js');
+const loadedlibs = {};
+/* export before requiring lualib.js */
const luaL_openlibs = function(L) {
- const loadedlibs = {
- [lualib.LUA_LOADLIBNAME]: loadlib.luaopen_package,
- [lualib.LUA_COLIBNAME]: lcorolib.luaopen_coroutine,
- [lualib.LUA_DBLIBNAME]: ldblib.luaopen_debug,
- [lualib.LUA_MATHLIBNAME]: lmathlib.luaopen_math,
- [lualib.LUA_OSLIBNAME]: loslib.luaopen_os,
- [lualib.LUA_STRLIBNAME]: lstrlib.luaopen_string,
- [lualib.LUA_TABLIBNAME]: ltablib.luaopen_table,
- [lualib.LUA_UTF8LIBNAME]: lutf8lib.luaopen_utf8,
- "_G": lbaselib.luaopen_base
- };
-
- if (typeof process !== "undefined") loadedlibs[lualib.LUA_IOLIBNAME] = require('./liolib.js').luaopen_io;
-
/* "require" functions from 'loadedlibs' and set results to global table */
for (let lib in loadedlibs) {
luaL_requiref(L, to_luastring(lib), loadedlibs[lib], 1);
lua_pop(L, 1); /* remove lib */
}
};
-
module.exports.luaL_openlibs = luaL_openlibs;
+
+const lualib = require('./lualib.js');
+const { luaopen_base } = require('./lbaselib.js');
+const { luaopen_coroutine } = require('./lcorolib.js');
+const { luaopen_debug } = require('./ldblib.js');
+const { luaopen_math } = require('./lmathlib.js');
+const { luaopen_package } = require('./loadlib.js');
+const { luaopen_os } = require('./loslib.js');
+const { luaopen_string } = require('./lstrlib.js');
+const { luaopen_table } = require('./ltablib.js');
+const { luaopen_utf8 } = require('./lutf8lib.js');
+
+loadedlibs["_G"] = luaopen_base,
+loadedlibs[lualib.LUA_LOADLIBNAME] = luaopen_package;
+loadedlibs[lualib.LUA_COLIBNAME] = luaopen_coroutine;
+loadedlibs[lualib.LUA_TABLIBNAME] = luaopen_table;
+loadedlibs[lualib.LUA_OSLIBNAME] = luaopen_os;
+loadedlibs[lualib.LUA_STRLIBNAME] = luaopen_string;
+loadedlibs[lualib.LUA_MATHLIBNAME] = luaopen_math;
+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;
diff --git a/src/lualib.js b/src/lualib.js
index 4e98432..78f441f 100644
--- a/src/lualib.js
+++ b/src/lualib.js
@@ -1,14 +1,15 @@
"use strict";
const {
- LUA_VERSION_MAJOR,
- LUA_VERSION_MINOR
+ LUA_VERSION_MAJOR,
+ LUA_VERSION_MINOR
} = require("./lua.js");
-const linit = require('./linit.js');
const LUA_VERSUFFIX = "_" + LUA_VERSION_MAJOR + "_" + LUA_VERSION_MINOR;
module.exports.LUA_VERSUFFIX = LUA_VERSUFFIX;
+module.exports.lua_assert = function(c) {};
+
const LUA_COLIBNAME = "coroutine";
module.exports.LUA_COLIBNAME = LUA_COLIBNAME;
module.exports.luaopen_coroutine = require("./lcorolib.js").luaopen_coroutine;
@@ -51,7 +52,5 @@ const LUA_LOADLIBNAME = "package";
module.exports.LUA_LOADLIBNAME = LUA_LOADLIBNAME;
module.exports.luaopen_package = require("./loadlib.js").luaopen_package;
+const linit = require('./linit.js');
module.exports.luaL_openlibs = linit.luaL_openlibs;
-
-/* customary export */
-module.exports.lua_assert = function(c) {};