aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-04 11:21:40 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-04 11:21:40 +1000
commit0447737eaa41565c8ffddbe3ec5650ce148c4be8 (patch)
tree05523b6a821957897416809758735640dca6d702
parentf12c7cc38ff89defef53f67577f5bbd4c07afc70 (diff)
downloadfengari-0447737eaa41565c8ffddbe3ec5650ce148c4be8.tar.gz
fengari-0447737eaa41565c8ffddbe3ec5650ce148c4be8.tar.bz2
fengari-0447737eaa41565c8ffddbe3ec5650ce148c4be8.zip
package library doesn't need to be for just node
-rw-r--r--src/linit.js14
-rw-r--r--src/loadlib.js36
2 files changed, 25 insertions, 25 deletions
diff --git a/src/linit.js b/src/linit.js
index 13e60e3..6cc48b1 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -15,6 +15,7 @@ const loadlib = require('./loadlib.js');
const lualib = require('./lualib.js');
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,
@@ -26,19 +27,6 @@ const loadedlibs = {
"_G": lbaselib.luaopen_base
};
-// Only with Node
-if (typeof require === "function") {
-
- let fs = false;
- try {
- fs = require('fs');
- } catch (e) {}
-
- if (fs) {
- loadedlibs[lualib.LUA_LOADLIBNAME] = loadlib.luaopen_package;
- }
-}
-
const luaL_openlibs = function(L) {
/* "require" functions from 'loadedlibs' and set results to global table */
for (let lib in loadedlibs) {
diff --git a/src/loadlib.js b/src/loadlib.js
index c22fee5..15b835d 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -3,9 +3,6 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
-const fs = require('fs');
-
-
const LUA_IGMARK = ["-".charCodeAt(0)];
const CLIBS = lua.to_luastring("__CLIBS__", true);
@@ -78,19 +75,34 @@ const noenv = function(L) {
return b;
};
-const readable = function(filename) {
- let fd = false;
+let readable = function(filename) {
+ return false;
+};
+// Only with Node
+if (typeof require === "function") {
+ let fs = false;
try {
- fd = fs.openSync(lua.to_jsstring(filename), 'r');
- } catch (e) {
- return false;
- }
+ fs = require('fs');
+ } catch (e) {}
- fs.closeSync(fd);
+ if (fs) {
+ readable = function(filename) {
+ let fd = false;
+
+ try {
+ fd = fs.openSync(lua.to_jsstring(filename), 'r');
+ } catch (e) {
+ return false;
+ }
+
+ fs.closeSync(fd);
+
+ return true;
+ };
+ }
+}
- return true;
-};
/* error codes for 'lookforfunc' */
const ERRLIB = 1;