From 6be8db07196c407cd321a7b04f5022939c4ffce3 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 18 Apr 2017 11:38:21 +0200 Subject: Cache all to_luastring of internal literals --- src/lmathlib.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/lmathlib.js') diff --git a/src/lmathlib.js b/src/lmathlib.js index 500331b..c052fcb 100644 --- a/src/lmathlib.js +++ b/src/lmathlib.js @@ -37,13 +37,13 @@ const math_random = function(L) { up = lauxlib.luaL_checkinteger(L, 2); break; } - default: return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments")); + default: return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments", true)); } /* random integer in the interval [low, up] */ - lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty")); + lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty", true)); lauxlib.luaL_argcheck(L, low >= 0 || up <= Number.MAX_SAFE_INTEGER + low, 1, - lua.to_luastring("interval too large")); + lua.to_luastring("interval too large", true)); r *= (up - low) + 1; lapi.lua_pushinteger(L, r + low); @@ -173,7 +173,7 @@ const math_rad = function(L) { const math_min = function(L) { let n = lapi.lua_gettop(L); /* number of arguments */ let imin = 1; /* index of current minimum value */ - lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected")); + lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true)); for (let i = 2; i <= n; i++){ if (lapi.lua_compare(L, i, imin, lua.LUA_OPLT)) imin = i; @@ -185,7 +185,7 @@ const math_min = function(L) { const math_max = function(L) { let n = lapi.lua_gettop(L); /* number of arguments */ let imax = 1; /* index of current minimum value */ - lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected")); + lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true)); for (let i = 2; i <= n; i++){ if (lapi.lua_compare(L, imax, i, lua.LUA_OPLT)) imax = i; @@ -211,7 +211,7 @@ const math_fmod = function(L) { if (lapi.lua_isinteger(L, 1) && lapi.lua_isinteger(L, 2)) { let d = lapi.lua_tointeger(L, 2); if (Math.abs(d) + 1 <= 1) { - lauxlib.luaL_argcheck(L, d !== 0, 2, lua.to_luastring("zero")); + lauxlib.luaL_argcheck(L, d !== 0, 2, lua.to_luastring("zero", true)); lapi.lua_pushinteger(L, 0); } else lapi.lua_pushinteger(L, lapi.lua_tointeger(L, 1) % d); @@ -265,13 +265,13 @@ const mathlib = { const luaopen_math = function(L) { lauxlib.luaL_newlib(L, mathlib); lapi.lua_pushnumber(L, Math.PI); - lapi.lua_setfield(L, -2, lua.to_luastring("pi")); + lapi.lua_setfield(L, -2, lua.to_luastring("pi", true)); lapi.lua_pushnumber(L, Number.MAX_VALUE); - lapi.lua_setfield(L, -2, lua.to_luastring("huge")); + lapi.lua_setfield(L, -2, lua.to_luastring("huge", true)); lapi.lua_pushinteger(L, Number.MAX_SAFE_INTEGER); - lapi.lua_setfield(L, -2, lua.to_luastring("maxinteger")); + lapi.lua_setfield(L, -2, lua.to_luastring("maxinteger", true)); lapi.lua_pushinteger(L, Number.MIN_SAFE_INTEGER); - lapi.lua_setfield(L, -2, lua.to_luastring("mininteger")); + lapi.lua_setfield(L, -2, lua.to_luastring("mininteger", true)); return 1; }; -- cgit v1.2.3-54-g00ecf