summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-26 15:38:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-26 15:38:28 -0300
commita77d263e86feea55529800028f960d7124c1385f (patch)
tree88bc21289c5ef341a7f3509c067524fea7003049
parent7cc40851e1d1a18a4c45fca31dbccd4206050b11 (diff)
downloadlua-a77d263e86feea55529800028f960d7124c1385f.tar.gz
lua-a77d263e86feea55529800028f960d7124c1385f.tar.bz2
lua-a77d263e86feea55529800028f960d7124c1385f.zip
unsigned-manipulation functions (lua_puhsunsigned, lua_tounsigned, etc.)
deprecated
-rw-r--r--lauxlib.c17
-rw-r--r--lauxlib.h21
-rw-r--r--lmathlib.c4
-rw-r--r--ltests.c5
-rw-r--r--lua.h23
-rw-r--r--luaconf.h8
6 files changed, 46 insertions, 32 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 06a5882d..0ad4cc59 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.262 2014/04/15 18:25:49 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.263 2014/05/12 21:44:17 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -413,26 +413,11 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {
413} 413}
414 414
415 415
416LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) {
417 int isnum;
418 lua_Unsigned d = lua_tounsignedx(L, arg, &isnum);
419 if (!isnum)
420 interror(L, arg);
421 return d;
422}
423
424
425LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, 416LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,
426 lua_Integer def) { 417 lua_Integer def) {
427 return luaL_opt(L, luaL_checkinteger, arg, def); 418 return luaL_opt(L, luaL_checkinteger, arg, def);
428} 419}
429 420
430
431LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int arg,
432 lua_Unsigned def) {
433 return luaL_opt(L, luaL_checkunsigned, arg, def);
434}
435
436/* }====================================================== */ 421/* }====================================================== */
437 422
438 423
diff --git a/lauxlib.h b/lauxlib.h
index d3ed988a..866f66af 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.123 2014/01/05 14:04:46 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.124 2014/04/15 18:25:49 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -46,9 +46,6 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
46LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); 46LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
47LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, 47LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
48 lua_Integer def); 48 lua_Integer def);
49LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int arg);
50LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int arg,
51 lua_Unsigned def);
52 49
53LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 50LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
54LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); 51LUALIB_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,
211#endif 208#endif
212 209
213 210
211/*
212** {============================================================
213** Compatibility with deprecated unsigned conversions
214** =============================================================
215*/
216#if defined(LUA_COMPAT_APIUNSIGNED)
217
218#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
219#define luaL_optunsigned(L,a,d) \
220 ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
221
222#endif
223/* }============================================================ */
224
225
226
214#endif 227#endif
215 228
216 229
diff --git a/lmathlib.c b/lmathlib.c
index 711f1d3a..1e5c3ede 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.102 2014/06/02 23:09:28 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.103 2014/06/18 12:35:53 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -257,7 +257,7 @@ static int math_random (lua_State *L) {
257 257
258 258
259static int math_randomseed (lua_State *L) { 259static int math_randomseed (lua_State *L) {
260 l_srand((unsigned int)luaL_checkunsigned(L, 1)); 260 l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));
261 (void)rand(); /* discard first value to avoid undesirable correlations */ 261 (void)rand(); /* discard first value to avoid undesirable correlations */
262 return 0; 262 return 0;
263} 263}
diff --git a/ltests.c b/ltests.c
index 25ada591..f72d413c 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.172 2014/06/17 17:13:29 roberto Exp roberto $ 2** $Id: ltests.c,v 2.173 2014/06/19 18:29:30 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1263,9 +1263,6 @@ static struct X { int x; } x;
1263 const char *s1 = lua_pushstring(L1, s); 1263 const char *s1 = lua_pushstring(L1, s);
1264 lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0); 1264 lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0);
1265 } 1265 }
1266 else if EQ("tounsigned") {
1267 lua_pushinteger(L1, (lua_Integer)lua_tounsigned(L1, getindex));
1268 }
1269 else if EQ("type") { 1266 else if EQ("type") {
1270 lua_pushstring(L1, luaL_typename(L1, getnum)); 1267 lua_pushstring(L1, luaL_typename(L1, getnum));
1271 } 1268 }
diff --git a/lua.h b/lua.h
index 5beb5411..812df98f 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.306 2014/05/13 19:40:28 roberto Exp roberto $ 2** $Id: lua.h,v 1.307 2014/06/10 17:41:38 roberto Exp roberto $
3** Lua - A Scripting Language 3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -175,7 +175,6 @@ LUA_API const char *(lua_typename) (lua_State *L, int tp);
175 175
176LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); 176LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
177LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); 177LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
178LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
179LUA_API int (lua_toboolean) (lua_State *L, int idx); 178LUA_API int (lua_toboolean) (lua_State *L, int idx);
180LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 179LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
181LUA_API size_t (lua_rawlen) (lua_State *L, int idx); 180LUA_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);
220LUA_API void (lua_pushnil) (lua_State *L); 219LUA_API void (lua_pushnil) (lua_State *L);
221LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 220LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
222LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 221LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
223LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
224LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l); 222LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
225LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); 223LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
226LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 224LUA_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);
326 324
327 325
328/* 326/*
329** =============================================================== 327** {==============================================================
330** some useful macros 328** some useful macros
331** =============================================================== 329** ===============================================================
332*/ 330*/
333 331
334#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL) 332#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
335#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL) 333#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
336#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
337 334
338#define lua_pop(L,n) lua_settop(L, -(n)-1) 335#define lua_pop(L,n) lua_settop(L, -(n)-1)
339 336
@@ -365,6 +362,22 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
365 362
366#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1)) 363#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
367 364
365/* }============================================================== */
366
367
368/*
369** {==============================================================
370** compatibility macros for unsigned conversions
371** ===============================================================
372*/
373#if defined(LUA_COMPAT_APIUNSIGNED)
374
375#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
376#define lua_tounsignedx(L,i,is) ((lua_Integer)lua_tointegerx(L,i,is))
377#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
378
379#endif
380/* }============================================================== */
368 381
369/* 382/*
370** {====================================================================== 383** {======================================================================
diff --git a/luaconf.h b/luaconf.h
index 45451660..65ee1eff 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.207 2014/06/10 19:21:20 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.208 2014/06/24 17:02:00 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -280,6 +280,12 @@
280*/ 280*/
281#define LUA_COMPAT_BITLIB 281#define LUA_COMPAT_BITLIB
282 282
283/*
284@@ LUA_COMPAT_APIUNSIGNED controls the presence of macros for
285** manipulating unsigned integers (lua_pushunsigned, lua_tounsigned, etc.)
286*/
287#define LUA_COMPAT_APIUNSIGNED
288
283 289
284/* 290/*
285@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a 291@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a