summaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-06-26 16:25:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-06-26 16:25:45 -0300
commit2b1fc1b38cd9a21d22ca10c5d4debc99b7fa93c9 (patch)
tree8c209cbb1ea968b5643998e53f8344cc8a6be576 /lbaselib.c
parentf01c12c8917ab2ac9ef6a491374e06ac0611ab92 (diff)
downloadlua-2b1fc1b38cd9a21d22ca10c5d4debc99b7fa93c9.tar.gz
lua-2b1fc1b38cd9a21d22ca10c5d4debc99b7fa93c9.tar.bz2
lua-2b1fc1b38cd9a21d22ca10c5d4debc99b7fa93c9.zip
with string cache, it is not that important for 'type' to avoid
'lua_pushstring'
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 40caaa94..caec7f64 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.309 2014/12/10 12:26:42 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.310 2015/03/28 19:14:47 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -198,12 +198,10 @@ static int luaB_collectgarbage (lua_State *L) {
198} 198}
199 199
200 200
201/*
202** This function has all type names as upvalues, to maximize performance.
203*/
204static int luaB_type (lua_State *L) { 201static int luaB_type (lua_State *L) {
205 luaL_checkany(L, 1); 202 int t = lua_type(L, 1);
206 lua_pushvalue(L, lua_upvalueindex(lua_type(L, 1) + 1)); 203 luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
204 lua_pushstring(L, lua_typename(L, t));
207 return 1; 205 return 1;
208} 206}
209 207
@@ -490,9 +488,9 @@ static const luaL_Reg base_funcs[] = {
490 {"setmetatable", luaB_setmetatable}, 488 {"setmetatable", luaB_setmetatable},
491 {"tonumber", luaB_tonumber}, 489 {"tonumber", luaB_tonumber},
492 {"tostring", luaB_tostring}, 490 {"tostring", luaB_tostring},
491 {"type", luaB_type},
493 {"xpcall", luaB_xpcall}, 492 {"xpcall", luaB_xpcall},
494 /* placeholders */ 493 /* placeholders */
495 {"type", NULL},
496 {"_G", NULL}, 494 {"_G", NULL},
497 {"_VERSION", NULL}, 495 {"_VERSION", NULL},
498 {NULL, NULL} 496 {NULL, NULL}
@@ -500,7 +498,6 @@ static const luaL_Reg base_funcs[] = {
500 498
501 499
502LUAMOD_API int luaopen_base (lua_State *L) { 500LUAMOD_API int luaopen_base (lua_State *L) {
503 int i;
504 /* open lib into global table */ 501 /* open lib into global table */
505 lua_pushglobaltable(L); 502 lua_pushglobaltable(L);
506 luaL_setfuncs(L, base_funcs, 0); 503 luaL_setfuncs(L, base_funcs, 0);
@@ -510,11 +507,6 @@ LUAMOD_API int luaopen_base (lua_State *L) {
510 /* set global _VERSION */ 507 /* set global _VERSION */
511 lua_pushliteral(L, LUA_VERSION); 508 lua_pushliteral(L, LUA_VERSION);
512 lua_setfield(L, -2, "_VERSION"); 509 lua_setfield(L, -2, "_VERSION");
513 /* set function 'type' with proper upvalues */
514 for (i = 0; i < LUA_NUMTAGS; i++) /* push all type names as upvalues */
515 lua_pushstring(L, lua_typename(L, i));
516 lua_pushcclosure(L, luaB_type, LUA_NUMTAGS);
517 lua_setfield(L, -2, "type");
518 return 1; 510 return 1;
519} 511}
520 512