diff options
author | daurnimator <quae@daurnimator.com> | 2017-06-09 16:43:34 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-06-09 16:43:34 +1000 |
commit | 78c840d4666622cf86c99db0abdcd4a7fb3ffc13 (patch) | |
tree | 334891ad1d40ddf0888d15f268bfa24e3035ce48 /src/loadlib.js | |
parent | 6de7c8c76cd90940278984f49198f281c6af274c (diff) | |
download | fengari-78c840d4666622cf86c99db0abdcd4a7fb3ffc13.tar.gz fengari-78c840d4666622cf86c99db0abdcd4a7fb3ffc13.tar.bz2 fengari-78c840d4666622cf86c99db0abdcd4a7fb3ffc13.zip |
src/loadlib.js: Use luaL_Buffer to build findloader error message
Diffstat (limited to 'src/loadlib.js')
-rw-r--r-- | src/loadlib.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/loadlib.js b/src/loadlib.js index d376c7a..dfa082a 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -324,7 +324,8 @@ const searcher_preload = function(L) { }; const findloader = function(L, name, ctx, k) { - let msg = []; /* to build error message */ + let msg = new lauxlib.luaL_Buffer(); /* to build error message */ + lauxlib.luaL_buffinit(L, msg); /* push 'package.searchers' to index 3 in the stack */ if (lua.lua_getfield(L, lua.lua_upvalueindex(1), lua.to_luastring("searchers", true)) !== lua.LUA_TTABLE) lauxlib.luaL_error(L, lua.to_luastring("'package.searchers' must be a table")); @@ -338,7 +339,7 @@ const findloader_cont = function(L, status, ctx) { if (status === lua.LUA_OK) { if (lua.lua_rawgeti(L, 3, ctx.i) === lua.LUA_TNIL) { /* no more searchers? */ lua.lua_pop(L, 1); /* remove nil */ - lua.lua_pushstring(L, ctx.msg); /* create error message */ + lauxlib.luaL_pushresult(ctx.msg); /* create error message */ lauxlib.luaL_error(L, lua.to_luastring("module '%s' not found:%s"), ctx.name, lua.lua_tostring(L, -1)); } lua.lua_pushstring(L, ctx.name); @@ -350,8 +351,7 @@ const findloader_cont = function(L, status, ctx) { break; /* module loader found */ else if (lua.lua_isstring(L, -2)) { /* searcher returned error message? */ lua.lua_pop(L, 1); /* remove extra return */ - ctx.msg.push(...lua.lua_tostring(L, -1)); - lua.lua_remove(L, -1); /* concatenate error message */ + lauxlib.luaL_addvalue(ctx.msg); /* concatenate error message */ } else lua.lua_pop(L, 2); /* remove both returns */ |