aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-10 15:24:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-10 15:24:12 -0300
commit561030c211a8de6b46554fca4df13925b38a4758 (patch)
treec38e53ad959986643f2daf59120ba54d80a275bb
parent5336cc9d6a431fb32b511ae4980cbd68789cec02 (diff)
downloadlua-561030c211a8de6b46554fca4df13925b38a4758.tar.gz
lua-561030c211a8de6b46554fca4df13925b38a4758.tar.bz2
lua-561030c211a8de6b46554fca4df13925b38a4758.zip
pack/unpack functions renamed dump/undump
-rw-r--r--lstrlib.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/lstrlib.c b/lstrlib.c
index a1b71c36..32ba2632 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.191 2014/03/31 18:38:26 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.192 2014/04/03 13:29:24 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -989,7 +989,7 @@ static int getintsize (lua_State *L, int arg) {
989} 989}
990 990
991 991
992static int packint (char *buff, lua_Integer n, int littleendian, int size) { 992static int dumpint (char *buff, lua_Integer n, int littleendian, int size) {
993 int i; 993 int i;
994 if (littleendian) { 994 if (littleendian) {
995 for (i = 0; i < size - 1; i++) { 995 for (i = 0; i < size - 1; i++) {
@@ -1005,18 +1005,18 @@ static int packint (char *buff, lua_Integer n, int littleendian, int size) {
1005 } 1005 }
1006 buff[i] = (n & MC); /* last byte */ 1006 buff[i] = (n & MC); /* last byte */
1007 /* test for overflow: OK if there are only zeros left in higher bytes, 1007 /* test for overflow: OK if there are only zeros left in higher bytes,
1008 or if there are only ones left and packed number is negative (signal 1008 or if there are only ones left and dumped number is negative (signal
1009 bit, the higher bit in last byte, is one) */ 1009 bit, the higher bit in last byte, is one) */
1010 return ((n & ~(lua_Integer)MC) == 0 || (n | SM) == ~(lua_Integer)0); 1010 return ((n & ~(lua_Integer)MC) == 0 || (n | SM) == ~(lua_Integer)0);
1011} 1011}
1012 1012
1013 1013
1014static int packint_l (lua_State *L) { 1014static int dumpint_l (lua_State *L) {
1015 char buff[MAXINTSIZE]; 1015 char buff[MAXINTSIZE];
1016 lua_Integer n = luaL_checkinteger(L, 1); 1016 lua_Integer n = luaL_checkinteger(L, 1);
1017 int size = getintsize(L, 2); 1017 int size = getintsize(L, 2);
1018 int endian = getendian(L, 3); 1018 int endian = getendian(L, 3);
1019 if (packint(buff, n, endian, size)) 1019 if (dumpint(buff, n, endian, size))
1020 lua_pushlstring(L, buff, size); 1020 lua_pushlstring(L, buff, size);
1021 else 1021 else
1022 luaL_error(L, "integer does not fit into given size (%d)", size); 1022 luaL_error(L, "integer does not fit into given size (%d)", size);
@@ -1030,7 +1030,7 @@ static int packint_l (lua_State *L) {
1030/* mask to check higher-order byte + signal bit of next (lower) byte */ 1030/* mask to check higher-order byte + signal bit of next (lower) byte */
1031#define HIGHERBYTE1 (HIGHERBYTE | (HIGHERBYTE >> 1)) 1031#define HIGHERBYTE1 (HIGHERBYTE | (HIGHERBYTE >> 1))
1032 1032
1033static int unpackint (const char *buff, lua_Integer *res, 1033static int undumpint (const char *buff, lua_Integer *res,
1034 int littleendian, int size) { 1034 int littleendian, int size) {
1035 lua_Integer n = 0; 1035 lua_Integer n = 0;
1036 int i; 1036 int i;
@@ -1057,7 +1057,7 @@ static int unpackint (const char *buff, lua_Integer *res,
1057} 1057}
1058 1058
1059 1059
1060static int unpackint_l (lua_State *L) { 1060static int undumpint_l (lua_State *L) {
1061 lua_Integer res; 1061 lua_Integer res;
1062 size_t len; 1062 size_t len;
1063 const char *s = luaL_checklstring(L, 1, &len); 1063 const char *s = luaL_checklstring(L, 1, &len);
@@ -1066,7 +1066,7 @@ static int unpackint_l (lua_State *L) {
1066 int endian = getendian(L, 4); 1066 int endian = getendian(L, 4);
1067 luaL_argcheck(L, 1 <= pos && (size_t)pos + size - 1 <= len, 1, 1067 luaL_argcheck(L, 1 <= pos && (size_t)pos + size - 1 <= len, 1,
1068 "string too short"); 1068 "string too short");
1069 if(unpackint(s + pos - 1, &res, endian, size)) 1069 if(undumpint(s + pos - 1, &res, endian, size))
1070 lua_pushinteger(L, res); 1070 lua_pushinteger(L, res);
1071 else 1071 else
1072 luaL_error(L, "result does not fit into a Lua integer"); 1072 luaL_error(L, "result does not fit into a Lua integer");
@@ -1096,7 +1096,7 @@ static int getfloatsize (lua_State *L, int arg) {
1096} 1096}
1097 1097
1098 1098
1099static int packfloat_l (lua_State *L) { 1099static int dumpfloat_l (lua_State *L) {
1100 float f; double d; 1100 float f; double d;
1101 char *pn; /* pointer to number */ 1101 char *pn; /* pointer to number */
1102 lua_Number n = luaL_checknumber(L, 1); 1102 lua_Number n = luaL_checknumber(L, 1);
@@ -1118,7 +1118,7 @@ static int packfloat_l (lua_State *L) {
1118} 1118}
1119 1119
1120 1120
1121static int unpackfloat_l (lua_State *L) { 1121static int undumpfloat_l (lua_State *L) {
1122 lua_Number res; 1122 lua_Number res;
1123 size_t len; 1123 size_t len;
1124 const char *s = luaL_checklstring(L, 1, &len); 1124 const char *s = luaL_checklstring(L, 1, &len);
@@ -1165,10 +1165,10 @@ static const luaL_Reg strlib[] = {
1165 {"reverse", str_reverse}, 1165 {"reverse", str_reverse},
1166 {"sub", str_sub}, 1166 {"sub", str_sub},
1167 {"upper", str_upper}, 1167 {"upper", str_upper},
1168 {"packfloat", packfloat_l}, 1168 {"dumpfloat", dumpfloat_l},
1169 {"packint", packint_l}, 1169 {"dumpint", dumpint_l},
1170 {"unpackfloat", unpackfloat_l}, 1170 {"undumpfloat", undumpfloat_l},
1171 {"unpackint", unpackint_l}, 1171 {"undumpint", undumpint_l},
1172 {NULL, NULL} 1172 {NULL, NULL}
1173}; 1173};
1174 1174