Răsfoiți Sursa

'debug.subtype' -> 'math.type' (to distinguish integers and floats)

Roberto Ierusalimschy 12 ani în urmă
părinte
comite
4244da96bf
2 a modificat fișierele cu 17 adăugiri și 35 ștergeri
  1. 1 34
      ldblib.c
  2. 16 1
      lmathlib.c

+ 1 - 34
ldblib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldblib.c,v 1.133 2013/06/25 19:37:00 roberto Exp roberto $
+** $Id: ldblib.c,v 1.134 2013/07/10 20:57:05 roberto Exp roberto $
 ** Interface from Lua to its debug API
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -34,38 +34,6 @@ static int db_numbits (lua_State *L) {
 }
 }
 
 
 
 
-static int db_subtype (lua_State *L) {
-  int tp = lua_type(L, 1);
-  switch (tp) {
-    case LUA_TNONE:
-      luaL_checkany(L, 1);
-      break;
-    case LUA_TNUMBER:
-      if (lua_isinteger(L, 1))
-        lua_pushliteral(L, "integer"); 
-      else
-        lua_pushliteral(L, "float"); 
-      break;
-    case LUA_TFUNCTION:
-      if (lua_iscfunction(L, 1))
-        lua_pushliteral(L, "Cfunction"); 
-      else
-        lua_pushliteral(L, "Luafunction"); 
-      break;
-    case LUA_TUSERDATA:
-      if (lua_islightuserdata(L, 1))
-        lua_pushliteral(L, "lightudata"); 
-      else
-        lua_pushliteral(L, "fulludata"); 
-      break;
-    default:
-      lua_pushstring(L, lua_typename(L, tp));
-      break;
-  }
-  return 1;
-}
-
-
 static int db_getregistry (lua_State *L) {
 static int db_getregistry (lua_State *L) {
   lua_pushvalue(L, LUA_REGISTRYINDEX);
   lua_pushvalue(L, LUA_REGISTRYINDEX);
   return 1;
   return 1;
@@ -431,7 +399,6 @@ static const luaL_Reg dblib[] = {
   {"setlocal", db_setlocal},
   {"setlocal", db_setlocal},
   {"setmetatable", db_setmetatable},
   {"setmetatable", db_setmetatable},
   {"setupvalue", db_setupvalue},
   {"setupvalue", db_setupvalue},
-  {"subtype", db_subtype},
   {"traceback", db_traceback},
   {"traceback", db_traceback},
   {NULL, NULL}
   {NULL, NULL}
 };
 };

+ 16 - 1
lmathlib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lmathlib.c,v 1.90 2013/07/03 17:23:19 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.91 2013/07/10 20:57:05 roberto Exp roberto $
 ** Standard mathematical library
 ** Standard mathematical library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -251,6 +251,20 @@ static int math_randomseed (lua_State *L) {
 }
 }
 
 
 
 
+static int math_type (lua_State *L) {
+  luaL_checkany(L, 1);
+  if (lua_type(L, 1) == LUA_TNUMBER) {
+      if (lua_isinteger(L, 1))
+        lua_pushliteral(L, "integer"); 
+      else
+        lua_pushliteral(L, "float"); 
+  }
+  else
+    lua_pushnil(L);
+  return 1;
+}
+
+
 static const luaL_Reg mathlib[] = {
 static const luaL_Reg mathlib[] = {
   {"abs",   math_abs},
   {"abs",   math_abs},
   {"acos",  math_acos},
   {"acos",  math_acos},
@@ -283,6 +297,7 @@ static const luaL_Reg mathlib[] = {
   {"sqrt",  math_sqrt},
   {"sqrt",  math_sqrt},
   {"tanh",   math_tanh},
   {"tanh",   math_tanh},
   {"tan",   math_tan},
   {"tan",   math_tan},
+  {"type", math_type},
   {NULL, NULL}
   {NULL, NULL}
 };
 };