summaryrefslogtreecommitdiff
path: root/src/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-18 11:38:21 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-18 11:38:21 +0200
commit6be8db07196c407cd321a7b04f5022939c4ffce3 (patch)
tree1e979f818d2139a23a749d8536d8cc12b4858037 /src/lbaselib.js
parent4f415e5ca594c5b60e6fa6315b69acb41273ee7e (diff)
downloadfengari-6be8db07196c407cd321a7b04f5022939c4ffce3.tar.gz
fengari-6be8db07196c407cd321a7b04f5022939c4ffce3.tar.bz2
fengari-6be8db07196c407cd321a7b04f5022939c4ffce3.zip
Cache all to_luastring of internal literals
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r--src/lbaselib.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 931a285..af7c3cc 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -13,14 +13,14 @@ const luaB_print = function(L) {
let n = lapi.lua_gettop(L); /* number of arguments */
let str = [];
- lapi.lua_getglobal(L, lua.to_luastring("tostring"));
+ lapi.lua_getglobal(L, lua.to_luastring("tostring", true));
for (let i = 1; i <= n; i++) {
lapi.lua_pushvalue(L, -1); /* function to be called */
lapi.lua_pushvalue(L, i); /* value to print */
lapi.lua_call(L, 1, 1);
let s = lapi.lua_tolstring(L, -1);
if (s === null)
- return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'"));
+ return lauxlib.luaL_error(L, lua.to_luastring("'tostring' must return a string to 'print'", true));
if (i > 1) s = ["\t".charCodeAt(0)].concat(s);
str = str.concat(s);
lapi.lua_pop(L, 1);
@@ -45,16 +45,16 @@ const luaB_getmetatable = function(L) {
lapi.lua_pushnil(L);
return 1; /* no metatable */
}
- lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable"));
+ lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true));
return 1; /* returns either __metatable field (if present) or metatable */
};
const luaB_setmetatable = function(L) {
let t = lapi.lua_type(L, 2);
lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
- lauxlib.luaL_argcheck(L, t === CT.LUA_TNIL || t === CT.LUA_TTABLE, 2, lua.to_luastring("nil or table expected"));
- if (lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable")) !== CT.LUA_TNIL)
- return lauxlib.luaL_error(L, lua.to_luastring("cannot change a protected metatable"));
+ lauxlib.luaL_argcheck(L, t === CT.LUA_TNIL || t === CT.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
+ if (lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true)) !== CT.LUA_TNIL)
+ return lauxlib.luaL_error(L, lua.to_luastring("cannot change a protected metatable", true));
lapi.lua_settop(L, 2);
lapi.lua_setmetatable(L, 1);
return 1;
@@ -69,7 +69,7 @@ const luaB_rawequal = function(L) {
const luaB_rawlen = function(L) {
let t = lapi.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t === CT.LUA_TTABLE || t === CT.LUA_TSTRING, 1, lua.to_luastring("table or string expected"));
+ lauxlib.luaL_argcheck(L, t === CT.LUA_TTABLE || t === CT.LUA_TSTRING, 1, lua.to_luastring("table or string expected", true));
lapi.lua_pushinteger(L, lapi.lua_rawlen(L, 1));
return 1;
};
@@ -93,7 +93,7 @@ const luaB_rawset = function(L) {
const luaB_type = function(L) {
let t = lapi.lua_type(L, 1);
- lauxlib.luaL_argcheck(L, t !== CT.LUA_TNONE, 1, lua.to_luastring("value expected"));
+ lauxlib.luaL_argcheck(L, t !== CT.LUA_TNONE, 1, lua.to_luastring("value expected", true));
lapi.lua_pushstring(L, lapi.lua_typename(L, t));
return 1;
};
@@ -124,7 +124,7 @@ const luaB_next = function(L) {
};
const luaB_pairs = function(L) {
- return pairsmeta(L, lua.to_luastring("__pairs"), 0, luaB_next);
+ return pairsmeta(L, lua.to_luastring("__pairs", true), 0, luaB_next);
};
/*
@@ -166,7 +166,7 @@ const luaB_tonumber = function(L) {
let base = lauxlib.luaL_checkinteger(L, 2);
lauxlib.luaL_checktype(L, 1, CT.LUA_TSTRING); /* no numbers as strings */
let s = lapi.lua_tostring(L, 1);
- lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, lua.to_luastring("base out of range"));
+ lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, lua.to_luastring("base out of range", true));
let n = parseInt(lobject.jsstring(s), base);
if (!isNaN(n)) {
lapi.lua_pushinteger(L, n);
@@ -210,7 +210,7 @@ const luaB_select = function(L) {
let i = lauxlib.luaL_checkinteger(L, 1);
if (i < 0) i = n + i;
else if (i > n) i = n;
- lauxlib.luaL_argcheck(L, 1 <= i, 1, lua.to_luastring("index out of range"));
+ lauxlib.luaL_argcheck(L, 1 <= i, 1, lua.to_luastring("index out of range", true));
return n - i;
}
};
@@ -284,28 +284,28 @@ const RESERVEDSLOT = 5;
** reserved slot inside the stack.
*/
const generic_reader = function(L, ud) {
- lauxlib.luaL_checkstack(L, 2, lua.to_luastring("too many nested functions"));
+ lauxlib.luaL_checkstack(L, 2, lua.to_luastring("too many nested functions", true));
lapi.lua_pushvalue(L, 1); /* get function */
lapi.lua_call(L, 0, 1); /* call it */
if (lapi.lua_isnil(L, -1)) {
lapi.lua_pop(L, 1); /* pop result */
return null;
} else if (!lapi.lua_isstring(L, -1))
- lauxlib.luaL_error(L, lua.to_luastring("reader function must return a string"));
+ lauxlib.luaL_error(L, lua.to_luastring("reader function must return a string", true));
lapi.lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
return lapi.lua_tostring(L, RESERVEDSLOT);
};
const luaB_load = function(L) {
let s = lapi.lua_tostring(L, 1);
- let mode = lauxlib.luaL_optstring(L, 3, lua.to_luastring("bt"));
+ let mode = lauxlib.luaL_optstring(L, 3, lua.to_luastring("bt", true));
let env = !lapi.lua_isnone(L, 4) ? 4 : 0; /* 'env' index or 0 if no 'env' */
let status;
if (s !== null) { /* loading a string? */
let chunkname = lauxlib.luaL_optstring(L, 2, s);
status = lauxlib.luaL_loadbufferx(L, s, chunkname, mode);
} else { /* loading from a reader function */
- let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)"));
+ let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
lauxlib.luaL_checktype(L, 1, CT.LUA_TFUNCTION);
lapi.lua_settop(L, RESERVEDSLOT); /* create reserved slot */
status = lapi.lua_load(L, generic_reader, null, chunkname, mode);
@@ -378,10 +378,10 @@ const luaopen_base = function(L) {
lauxlib.luaL_setfuncs(L, base_funcs, 0);
/* set global _G */
lapi.lua_pushvalue(L, -1);
- lapi.lua_setfield(L, -2, lua.to_luastring("_G"));
+ lapi.lua_setfield(L, -2, lua.to_luastring("_G", true));
/* set global _VERSION */
lapi.lua_pushliteral(L, lua.LUA_VERSION);
- lapi.lua_setfield(L, -2, lua.to_luastring("_VERSION"));
+ lapi.lua_setfield(L, -2, lua.to_luastring("_VERSION", true));
return 1;
};