From fcfa9dafbd6cc57c9259d0f0ae5f3aaa32ddd8d1 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 27 Sep 2017 23:05:03 +1000 Subject: src/loadlib.js: Use sourceURL to get path in debugger+tracebacks --- src/loadlib.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/loadlib.js b/src/loadlib.js index a7b27af..e7626ab 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -38,14 +38,19 @@ const AUXMARK = [1]; let lsys_load; if (WEB) { lsys_load = function(L, path, seeglb) { + path = lua.to_jsstring(path); let xhr = new XMLHttpRequest(); - xhr.open("GET", lua.to_jsstring(path), false); + xhr.open("GET", path, false); xhr.send(); if (xhr.status >= 200 && xhr.status <= 299) { + let code = xhr.response; + /* Add sourceURL comment to get path in debugger+tracebacks */ + if (!/\/\/[#@] sourceURL=/.test(code)) + code += " //# sourceURL=" + path; let func; try { - func = Function("fengari", xhr.response); + func = Function("fengari", code); } catch (e) { lua.lua_pushstring(L, lua.to_luastring(`${e.name}: ${e.message}`)); return null; -- cgit v1.2.3-70-g09d2