unsigned-manipulation functions (lua_puhsunsigned, lua_tounsigned, etc.)

deprecated
This commit is contained in:
Roberto Ierusalimschy 2014-06-26 15:38:28 -03:00
parent 7cc40851e1
commit a77d263e86
6 changed files with 46 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.262 2014/04/15 18:25:49 roberto Exp roberto $
** $Id: lauxlib.c,v 1.263 2014/05/12 21:44:17 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -413,26 +413,11 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {
}
LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) {
int isnum;
lua_Unsigned d = lua_tounsignedx(L, arg, &isnum);
if (!isnum)
interror(L, arg);
return d;
}
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,
lua_Integer def) {
return luaL_opt(L, luaL_checkinteger, arg, def);
}
LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int arg,
lua_Unsigned def) {
return luaL_opt(L, luaL_checkunsigned, arg, def);
}
/* }====================================================== */

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.123 2014/01/05 14:04:46 roberto Exp roberto $
** $Id: lauxlib.h,v 1.124 2014/04/15 18:25:49 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -46,9 +46,6 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int arg);
LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int arg,
lua_Unsigned def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
@ -211,6 +208,22 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
#endif
/*
** {============================================================
** Compatibility with deprecated unsigned conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIUNSIGNED)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#endif
/* }============================================================ */
#endif

View File

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.102 2014/06/02 23:09:28 roberto Exp roberto $
** $Id: lmathlib.c,v 1.103 2014/06/18 12:35:53 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@ -257,7 +257,7 @@ static int math_random (lua_State *L) {
static int math_randomseed (lua_State *L) {
l_srand((unsigned int)luaL_checkunsigned(L, 1));
l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));
(void)rand(); /* discard first value to avoid undesirable correlations */
return 0;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.172 2014/06/17 17:13:29 roberto Exp roberto $
** $Id: ltests.c,v 2.173 2014/06/19 18:29:30 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -1263,9 +1263,6 @@ static struct X { int x; } x;
const char *s1 = lua_pushstring(L1, s);
lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0);
}
else if EQ("tounsigned") {
lua_pushinteger(L1, (lua_Integer)lua_tounsigned(L1, getindex));
}
else if EQ("type") {
lua_pushstring(L1, luaL_typename(L1, getnum));
}

23
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.306 2014/05/13 19:40:28 roberto Exp roberto $
** $Id: lua.h,v 1.307 2014/06/10 17:41:38 roberto Exp roberto $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -175,7 +175,6 @@ LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
@ -220,7 +219,6 @@ LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
@ -326,14 +324,13 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** ===============================================================
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
@ -365,6 +362,22 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros for unsigned conversions
** ===============================================================
*/
#if defined(LUA_COMPAT_APIUNSIGNED)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Integer)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
/* }============================================================== */
/*
** {======================================================================

View File

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.207 2014/06/10 19:21:20 roberto Exp roberto $
** $Id: luaconf.h,v 1.208 2014/06/24 17:02:00 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -280,6 +280,12 @@
*/
#define LUA_COMPAT_BITLIB
/*
@@ LUA_COMPAT_APIUNSIGNED controls the presence of macros for
** manipulating unsigned integers (lua_pushunsigned, lua_tounsigned, etc.)
*/
#define LUA_COMPAT_APIUNSIGNED
/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a