diff options
author | daurnimator <quae@daurnimator.com> | 2017-12-12 15:03:02 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-12-13 15:03:54 +1100 |
commit | e438f10592077f8b5432f67ef72a8f1bfbbcdc49 (patch) | |
tree | 7755e33334b592e78bc76a20a47fb5e504fe7c74 /src | |
parent | c5b39b9d292c1a2178aa41c6a95367a81614eb61 (diff) | |
download | fengari-e438f10592077f8b5432f67ef72a8f1bfbbcdc49.tar.gz fengari-e438f10592077f8b5432f67ef72a8f1bfbbcdc49.tar.bz2 fengari-e438f10592077f8b5432f67ef72a8f1bfbbcdc49.zip |
src/: Use to_luastring more often instead of manually creating arrays
Diffstat (limited to 'src')
-rw-r--r-- | src/lapi.js | 2 | ||||
-rw-r--r-- | src/lauxlib.js | 8 | ||||
-rw-r--r-- | src/lbaselib.js | 2 | ||||
-rw-r--r-- | src/ldblib.js | 4 | ||||
-rw-r--r-- | src/ldebug.js | 12 | ||||
-rw-r--r-- | src/loadlib.js | 10 | ||||
-rw-r--r-- | src/lobject.js | 2 | ||||
-rw-r--r-- | src/ltablib.js | 4 |
8 files changed, 22 insertions, 22 deletions
diff --git a/src/lapi.js b/src/lapi.js index 3726af0..9e2f0a3 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -230,7 +230,7 @@ const lua_pushinteger = function(L, n) { assert(L.top <= L.ci.top, "stack overflow"); }; -const emptystring = []; +const emptystring = defs.to_luastring(""); const lua_pushlstring = function(L, s, len) { assert(typeof len === "number"); diff --git a/src/lauxlib.js b/src/lauxlib.js index 0c42a05..32dd37c 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -56,7 +56,7 @@ const findfield = function(L, objidx, level) { */ const pushglobalfuncname = function(L, ar) { let top = lua.lua_gettop(L); - lua.lua_getinfo(L, ['f'.charCodeAt(0)], ar); /* push function */ + lua.lua_getinfo(L, lua.to_luastring("f"), ar); /* push function */ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, LUA_LOADED_TABLE); if (findfield(L, top + 1, 2)) { let name = lua.lua_tostring(L, -1); @@ -146,7 +146,7 @@ const luaL_argerror = function(L, arg, extramsg) { if (!lua.lua_getstack(L, 0, ar)) /* no stack frame? */ return luaL_error(L, lua.to_luastring("bad argument #%d (%s)"), arg, extramsg); - lua.lua_getinfo(L, ['n'.charCodeAt(0)], ar); + lua.lua_getinfo(L, lua.to_luastring("n"), ar); if (ar.namewhat.join() === lua.to_luastring("method").join()) { arg--; /* do not count 'self' */ @@ -155,7 +155,7 @@ const luaL_argerror = function(L, arg, extramsg) { } if (ar.name === null) - ar.name = pushglobalfuncname(L, ar) ? lua.lua_tostring(L, -1) : ["?".charCodeAt(0)]; + ar.name = pushglobalfuncname(L, ar) ? lua.lua_tostring(L, -1) : lua.to_luastring("?"); return luaL_error(L, lua.to_luastring("bad argument #%d to '%s' (%s)"), arg, ar.name, extramsg); }; @@ -182,7 +182,7 @@ const luaL_where = function(L, level) { return; } } - lua.lua_pushstring(L, []); + lua.lua_pushstring(L, lua.to_luastring("")); }; const luaL_error = function(L, fmt, ...argp) { diff --git a/src/lbaselib.js b/src/lbaselib.js index 54e73b1..ca95e98 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -32,7 +32,7 @@ const luaB_print = function(L) { let s = lua.lua_tolstring(L, -1); if (s === null) return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'", true)); - if (i > 1) lua_writestring(["\t".charCodeAt(0)]); + if (i > 1) lua_writestring(lua.to_luastring("\t")); lua_writestring(s); lua.lua_pop(L, 1); } diff --git a/src/ldblib.js b/src/ldblib.js index 96db3c7..746d3bf 100644 --- a/src/ldblib.js +++ b/src/ldblib.js @@ -281,7 +281,7 @@ const hookf = function(L, ar) { if (ar.currentline >= 0) lua.lua_pushinteger(L, ar.currentline); /* push current line */ else lua.lua_pushnil(L); - assert(lua.lua_getinfo(L, ["l".charCodeAt(0), "S".charCodeAt(0)], ar)); + assert(lua.lua_getinfo(L, lua.to_luastring("lS"), ar)); lua.lua_call(L, 2, 0); /* call hook function */ } }; @@ -328,7 +328,7 @@ const db_sethook = function(L) { lua.lua_createtable(L, 0, 2); /* create a hook table */ lua.lua_pushvalue(L, -1); lua.lua_rawsetp(L, lua.LUA_REGISTRYINDEX, HOOKKEY); /* set it in position */ - lua.lua_pushstring(L, ["k".charCodeAt(0)]); + lua.lua_pushstring(L, lua.to_luastring("k")); lua.lua_setfield(L, -2, lua.to_luastring("__mode", true)); /** hooktable.__mode = "k" */ lua.lua_pushvalue(L, -1); lua.lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ diff --git a/src/ldebug.js b/src/ldebug.js index e5265e4..58bccc9 100644 --- a/src/ldebug.js +++ b/src/ldebug.js @@ -86,7 +86,7 @@ const lua_getstack = function(L, level, ar) { const upvalname = function(p, uv) { assert(uv < p.upvalues.length); let s = p.upvalues[uv].name; - if (s === null) return ["?".charCodeAt(0)]; + if (s === null) return defs.to_luastring("?", true); return s.getstr(); }; @@ -170,7 +170,7 @@ const funcinfo = function(ar, cl) { ar.source = defs.to_luastring("=[JS]", true); ar.linedefined = -1; ar.lastlinedefined = -1; - ar.what = ["J".charCodeAt(0)]; + ar.what = defs.to_luastring("J", true); } else { let p = cl.p; ar.source = p.source ? p.source.getstr() : defs.to_luastring("=?", true); @@ -247,7 +247,7 @@ const auxgetinfo = function(L, what, ar, f, ci) { case 'n': { let r = getfuncname(L, ci); if (r === null) { - ar.namewhat = []; + ar.namewhat = defs.to_luastring(""); ar.name = null; } else { ar.namewhat = r.funcname; @@ -314,7 +314,7 @@ const kname = function(p, pc, c) { } /* else no reasonable name found */ } - r.name = [defs.char["?"]]; + r.name = defs.to_luastring("?", true); return r; /* no reasonable name found */ }; @@ -452,7 +452,7 @@ const funcnamefromcode = function(L, ci) { let OCi = lopcodes.OpCodesI; if (ci.callstatus & lstate.CIST_HOOKED) { - r.name = [defs.char["?"]]; + r.name = defs.to_luastring("?", true); r.funcname = defs.to_luastring("hook", true); return r; } @@ -578,7 +578,7 @@ const luaG_addinfo = function(L, msg, src, line) { if (src) buff = lobject.luaO_chunkid(src.getstr(), luaconf.LUA_IDSIZE); else - buff = ['?'.charCodeAt(0)]; + buff = defs.to_luastring("?", true); return lobject.luaO_pushfstring(L, defs.to_luastring("%s:%d: %s", true), buff, line, msg); }; diff --git a/src/loadlib.js b/src/loadlib.js index a64f1c3..bae5db1 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -26,7 +26,7 @@ const LUA_POF = lua.to_luastring("luaopen_"); const LUA_OFSEP = lua.to_luastring("_"); const LIB_FAIL = "open"; -const AUXMARK = [1]; +const AUXMARK = lua.to_luastring("\x01"); /* @@ -277,8 +277,8 @@ const ll_searchpath = function(L) { L, lauxlib.luaL_checkstring(L, 1), lauxlib.luaL_checkstring(L, 2), - lauxlib.luaL_optstring(L, 3, [".".charCodeAt(0)]), - lauxlib.luaL_optstring(L, 4, [lua.LUA_DIRSEP.charCodeAt(0)]) + lauxlib.luaL_optstring(L, 3, lua.to_luastring(".")), + lauxlib.luaL_optstring(L, 4, lua.to_luastring(lua.LUA_DIRSEP)) ); if (f !== null) return 1; else { /* error message is on top of the stack */ @@ -293,7 +293,7 @@ const findfile = function(L, name, pname, dirsep) { let path = lua.lua_tostring(L, -1); if (path === null) lauxlib.luaL_error(L, lua.to_luastring("'package.%s' must be a string"), pname); - return searchpath(L, name, path, ['.'.charCodeAt(0)], dirsep); + return searchpath(L, name, path, lua.to_luastring("."), dirsep); }; const checkload = function(L, stat, filename) { @@ -322,7 +322,7 @@ const searcher_Lua = function(L) { */ const loadfunc = function(L, filename, modname) { let openfunc; - modname = lauxlib.luaL_gsub(L, modname, [".".charCodeAt(0)], LUA_OFSEP); + modname = lauxlib.luaL_gsub(L, modname, lua.to_luastring("."), LUA_OFSEP); let mark = modname.indexOf(LUA_IGMARK.charCodeAt(0)); if (mark >= 0) { openfunc = lua.lua_pushlstring(L, modname, mark); diff --git a/src/lobject.js b/src/lobject.js index d816323..a67147a 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -600,7 +600,7 @@ const luaO_pushvfstring = function(L, fmt, argp) { pushstr(L, defs.to_luastring(String.fromCodePoint(argp[a++]))); break; case char['%']: - pushstr(L, [char['%']]); + pushstr(L, defs.to_luastring("%", true)); break; default: ldebug.luaG_runerror(L, defs.to_luastring("invalid option '%%%c' to 'lua_pushfstring'"), fmt[e + 1]); diff --git a/src/ltablib.js b/src/ltablib.js index 05c9c09..70ff595 100644 --- a/src/ltablib.js +++ b/src/ltablib.js @@ -130,7 +130,7 @@ const tmove = function(L) { const tconcat = function(L) { let last = aux_getn(L, 1, TAB_R); - let sep = lauxlib.luaL_optlstring(L, 2, []); + let sep = lauxlib.luaL_optlstring(L, 2, lua.to_luastring("")); let i = lauxlib.luaL_optinteger(L, 3, 1); last = lauxlib.luaL_optinteger(L, 4, last); @@ -157,7 +157,7 @@ const pack = function(L) { for (let i = n; i >= 1; i--) /* assign elements */ lua.lua_seti(L, 1, i); lua.lua_pushinteger(L, n); - lua.lua_setfield(L, 1, ["n".charCodeAt(0)]); /* t.n = number of elements */ + lua.lua_setfield(L, 1, lua.to_luastring("n")); /* t.n = number of elements */ return 1; /* return table */ }; |