aboutsummaryrefslogtreecommitdiff
path: root/src/loadlib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-05 10:33:23 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-05 10:33:23 +1000
commitb600ba0123b8af27d2d25e7655b311163afaec91 (patch)
tree082377211fe92fdd2e60c521aecaf0ad2cd64f6f /src/loadlib.js
parent84a0982085967895e9bb5e5439c09960840da2d5 (diff)
downloadfengari-b600ba0123b8af27d2d25e7655b311163afaec91.tar.gz
fengari-b600ba0123b8af27d2d25e7655b311163afaec91.tar.bz2
fengari-b600ba0123b8af27d2d25e7655b311163afaec91.zip
Fix luaL_error callsites
- Now that luaL_error does sprintf-like formatting it shouldn't take user input - % now needs to be escaped when passed to luaL_error - Removes several wasteful lua->js->lua string transformations
Diffstat (limited to 'src/loadlib.js')
-rw-r--r--src/loadlib.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/loadlib.js b/src/loadlib.js
index 7213796..e7b1680 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -249,7 +249,7 @@ const findfile = function(L, name, pname, dirsep) {
lua.lua_getfield(L, lua.lua_upvalueindex(1), pname);
let path = lua.lua_tostring(L, -1);
if (path === null)
- lauxlib.luaL_error(L, `'package.${lua.to_jsstring(pname)}' must be a string`);
+ lauxlib.luaL_error(L, lua.to_luastring("'package.%s' must be a string"), pname);
return searchpath(L, name, path, ['.'.charCodeAt(0)], dirsep);
};
@@ -258,7 +258,8 @@ const checkload = function(L, stat, filename) {
lua.lua_pushstring(L, filename); /* will be 2nd argument to module */
return 2; /* return open function and file name */
} else
- return lauxlib.luaL_error(L, lua.to_luastring(`error loading module '${lua.lua_tojsstring(L, 1)}' from file '${lua.to_jsstring(filename)}':\n\t${lua.lua_tojsstring(L, 1)}`));
+ return lauxlib.luaL_error(L, lua.to_luastring("error loading module '%s' from file '%s':\n\t%s"),
+ lua.lua_tostring(L, 1), filename, lua.lua_tostring(L, 1));
};
const searcher_Lua = function(L) {
@@ -336,7 +337,7 @@ const findloader = function(L, name) {
if (lua.lua_rawgeti(L, 3, i) === lua.LUA_TNIL) { /* no more searchers? */
lua.lua_pop(L, 1); /* remove nil */
lua.lua_pushstring(L, msg); /* create error message */
- lauxlib.luaL_error(L, lua.to_luastring(`module '${lua.to_jsstring(name)}' not found:${lua.lua_tojsstring(L, -1)}`));
+ lauxlib.luaL_error(L, lua.to_luastring("module '%s' not found:%s"), name, lua.lua_tostring(L, -1));
}
lua.lua_pushstring(L, name);
lua.lua_call(L, 1, 2); /* call it */