From 1c9d5cce74d26d1bfbf24f270f8e92c70cfa0b28 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 17 Aug 2017 15:39:55 +1000 Subject: src/loslib.js: Tidy up node specific function definitions --- src/loslib.js | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/loslib.js b/src/loslib.js index a35f150..aecb647 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -151,7 +151,11 @@ const syslib = { // Only with Node if (!WEB) { - const os_exit = function(L) { + const fs = require('fs'); + const tmp = require('tmp'); + const child_process = require('child_process'); + + syslib.exit = function(L) { let status; if (lua.lua_isboolean(L, 1)) status = (lua.lua_toboolean(L, 1) ? 0 : 1); @@ -163,35 +167,22 @@ if (!WEB) { return 0; }; - const os_getenv = function(L) { + syslib.getenv = function(L) { lua.lua_pushliteral(L, process.env[lua.to_jsstring(lauxlib.luaL_checkstring(L, 1))]); /* if NULL push nil */ return 1; }; - const os_clock = function(L) { + syslib.clock = function(L) { lua.lua_pushnumber(L, process.uptime()); return 1; }; - syslib.clock = os_clock; - syslib.exit = os_exit; - syslib.getenv = os_getenv; -} - - -// Only with Node -if (!WEB) { - - const fs = require('fs'); - const tmp = require('tmp'); - const child_process = require('child_process'); - // TODO: on POSIX system, should create the file const lua_tmpname = function() { return tmp.tmpNameSync(); }; - const os_remove = function(L) { + syslib.remove = function(L) { let filename = lauxlib.luaL_checkstring(L, 1); try { if (fs.lstatSync(lua.to_jsstring(filename)).isDirectory()) { @@ -205,7 +196,7 @@ if (!WEB) { return lauxlib.luaL_fileresult(L, true); }; - const os_rename = function(L) { + syslib.rename = function(L) { let fromname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 1)); let toname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 2)); try { @@ -216,7 +207,7 @@ if (!WEB) { return lauxlib.luaL_fileresult(L, true); }; - const os_tmpname = function(L) { + syslib.tmpname = function(L) { let name = lua_tmpname(); if (!name) return lauxlib.luaL_error(L, lua.to_luastring("unable to generate a unique filename")); @@ -224,11 +215,7 @@ if (!WEB) { return 1; }; - syslib.remove = os_remove; - syslib.rename = os_rename; - syslib.tmpname = os_tmpname; - - const os_execute = function(L) { + syslib.execute = function(L) { let cmd = lauxlib.luaL_optstring(L, 1, null); if (cmd !== null) { try { @@ -259,9 +246,6 @@ if (!WEB) { return 1; } }; - - syslib.execute = os_execute; - } const luaopen_os = function(L) { -- cgit v1.2.3-54-g00ecf