From fadf3105964c5c65f06e9c561f4872be810080a9 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 12 Nov 2017 20:37:34 +1100 Subject: src/loslib.js: Remove to_jsstring where possible --- src/loslib.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/loslib.js b/src/loslib.js index 42723c8..745bbab 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -176,7 +176,9 @@ if (!WEB) { }; syslib.getenv = function(L) { - lua.lua_pushliteral(L, process.env[lua.to_jsstring(lauxlib.luaL_checkstring(L, 1))]); /* if NULL push nil */ + let key = lauxlib.luaL_checkstring(L, 1); + key = lua.to_jsstring(key); /* https://github.com/nodejs/node/issues/16961 */ + lua.lua_pushliteral(L, process.env[key]); /* if NULL push nil */ return 1; }; @@ -193,10 +195,11 @@ if (!WEB) { syslib.remove = function(L) { let filename = lauxlib.luaL_checkstring(L, 1); try { - if (fs.lstatSync(lua.to_jsstring(filename)).isDirectory()) { - fs.rmdirSync(lua.to_jsstring(filename)); + filename = Uint8Array.from(filename); + if (fs.lstatSync(filename).isDirectory()) { + fs.rmdirSync(filename); } else { - fs.unlinkSync(lua.to_jsstring(filename)); + fs.unlinkSync(filename); } } catch (e) { return lauxlib.luaL_fileresult(L, false, filename, e); @@ -205,9 +208,11 @@ if (!WEB) { }; syslib.rename = function(L) { - let fromname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 1)); - let toname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 2)); + let fromname = lauxlib.luaL_checkstring(L, 1); + let toname = lauxlib.luaL_checkstring(L, 2); try { + fromname = Uint8Array.from(fromname); + toname = Uint8Array.from(toname); fs.renameSync(fromname, toname); } catch (e) { return lauxlib.luaL_fileresult(L, false, false, e); @@ -228,7 +233,7 @@ if (!WEB) { if (cmd !== null) { try { child_process.execSync( - lua.to_jsstring(cmd), + Uint8Array.from(cmd), { stdio: [process.stdin, process.stdout, process.stderr] } @@ -241,7 +246,7 @@ if (!WEB) { } else { try { child_process.execSync( - lua.to_jsstring(cmd), + Uint8Array.from(cmd), { stdio: [process.stdin, process.stdout, process.stderr] } -- cgit v1.2.3-70-g09d2