From 382bfe27205d5ade172fa088fcab0b2e123838e4 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 10 Dec 2017 01:01:43 +1100 Subject: Use `typeof process === "undefined"` instead of WEB global This removes requirement to set global.WEB before requiring in node --- src/defs.js | 2 +- src/lauxlib.js | 6 +++--- src/lbaselib.js | 2 +- src/ldblib.js | 3 +-- src/linit.js | 2 +- src/loadlib.js | 8 +++----- src/loslib.js | 2 +- src/lualib.js | 2 +- 8 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/defs.js b/src/defs.js index 3ebb747..268e76e 100644 --- a/src/defs.js +++ b/src/defs.js @@ -291,7 +291,7 @@ module.exports.LUA_EXEC_DIR = LUA_EXEC_DIR; const LUA_VDIR = LUA_VERSION_MAJOR + "." + LUA_VERSION_MINOR; module.exports.LUA_VDIR = LUA_VDIR; -if (WEB) { +if (typeof process === "undefined") { const LUA_DIRSEP = "/"; module.exports.LUA_DIRSEP = LUA_DIRSEP; diff --git a/src/lauxlib.js b/src/lauxlib.js index d976cee..f95f9a8 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -708,13 +708,13 @@ class LoadF { constructor() { this.n = NaN; /* number of pre-read characters */ this.f = null; /* file being read */ - this.buff = WEB ? new Array(1024) : new Buffer(1024); /* area for reading file */ + this.buff = typeof process === "undefined" ? new Array(1024) : new Buffer(1024); /* area for reading file */ this.pos = 0; /* current position in file */ this.err = void 0; } } -if (WEB) { +if (typeof process === "undefined") { const getF = function(L, ud) { let lf = ud; @@ -858,7 +858,7 @@ const luaL_dofile = function(L, filename) { const lua_writestringerror = function() { for (let i=0; i ' diff --git a/src/linit.js b/src/linit.js index 90ad978..97cbfc9 100644 --- a/src/linit.js +++ b/src/linit.js @@ -26,7 +26,7 @@ const luaL_openlibs = function(L) { "_G": lbaselib.luaopen_base }; - if (!WEB) loadedlibs[lualib.LUA_IOLIBNAME] = require('./liolib.js').luaopen_io; + 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) { diff --git a/src/loadlib.js b/src/loadlib.js index dbd5c3c..ef39f4f 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -36,7 +36,7 @@ const AUXMARK = [1]; ** error string in the stack. */ let lsys_load; -if (WEB) { +if (typeof process === "undefined") { lsys_load = function(L, path, seeglb) { path = lua.to_uristring(path); let xhr = new XMLHttpRequest(); @@ -111,9 +111,7 @@ const noenv = function(L) { }; let readable; -// Only with Node -if (!WEB) { - +if (typeof process !== "undefined") { // Only with Node const fs = require('fs'); readable = function(filename) { @@ -189,7 +187,7 @@ const ll_loadlib = function(L) { }; let env; -if (WEB) { +if (typeof process === "undefined") { env = window; } else { env = process.env; diff --git a/src/loslib.js b/src/loslib.js index 4b147cf..16df4ea 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -157,7 +157,7 @@ const syslib = { "time": os_time }; -if (WEB) { +if (typeof process === "undefined") { syslib.clock = function(L) { lua.lua_pushnumber(L, performance.now()/1000); return 1; diff --git a/src/lualib.js b/src/lualib.js index 50ca433..4fbae44 100644 --- a/src/lualib.js +++ b/src/lualib.js @@ -14,7 +14,7 @@ const LUA_TABLIBNAME = "table"; module.exports.LUA_TABLIBNAME = LUA_TABLIBNAME; module.exports.luaopen_table = require("./ltablib.js").luaopen_table; -if (!WEB) { +if (typeof process !== "undefined") { const LUA_IOLIBNAME = "io"; module.exports.LUA_IOLIBNAME = LUA_IOLIBNAME; module.exports.luaopen_io = require("./liolib.js").luaopen_io; -- cgit v1.2.3-54-g00ecf