From 389630abe2f44e122d29af7159dd1a0d5c585d15 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 18 Aug 2017 11:04:55 +1000 Subject: src/loadlib.js: Use path.resolve to construct paths --- src/loadlib.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/loadlib.js b/src/loadlib.js index e7cc7d3..acdf514 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -49,14 +49,12 @@ if (WEB) { } }; } else { + const pathlib = require('path'); lsys_load = function(L, path) { + path = lua.to_jsstring(path); + /* relative paths should be relative to cwd, not this js file */ + path = pathlib.resolve(process.cwd(), path); try { - path = lua.to_jsstring(path); - - // Relative path ? - if (path.startsWith('.')) - path = `${process.env.PWD}/${path}`; - return require(path); } catch (e) { lua.lua_pushstring(L, lua.to_luastring(e.message)); -- cgit v1.2.3-70-g09d2