diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-01-09 14:21:28 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-01-09 14:21:28 -0200 |
commit | 916bd874ad7270a89ae07fc76ddac00a34272fe9 (patch) | |
tree | ec1d03d008a43e66dd9d5bd21b7af7fca3eb09c9 | |
parent | cd848cab6bf59314d6b41625bbae918103f654db (diff) | |
download | lua-916bd874ad7270a89ae07fc76ddac00a34272fe9.tar.gz lua-916bd874ad7270a89ae07fc76ddac00a34272fe9.tar.bz2 lua-916bd874ad7270a89ae07fc76ddac00a34272fe9.zip |
added explicit default options to string.pack/unpack functions
-rw-r--r-- | lstrlib.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.183 2014/01/05 14:05:58 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.184 2014/01/08 18:34:34 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 | */ |
@@ -970,14 +970,17 @@ static union { | |||
970 | static int getendian (lua_State *L, int arg) { | 970 | static int getendian (lua_State *L, int arg) { |
971 | const char *endian = luaL_optstring(L, arg, | 971 | const char *endian = luaL_optstring(L, arg, |
972 | (nativeendian.little ? "l" : "b")); | 972 | (nativeendian.little ? "l" : "b")); |
973 | if (*endian == 'n') /* native? */ | ||
974 | return nativeendian.little; | ||
973 | luaL_argcheck(L, *endian == 'l' || *endian == 'b', arg, | 975 | luaL_argcheck(L, *endian == 'l' || *endian == 'b', arg, |
974 | "endianess must be 'l' or 'b'"); | 976 | "endianess must be 'l'/'b'/'n'"); |
975 | return (*endian == 'l'); | 977 | return (*endian == 'l'); |
976 | } | 978 | } |
977 | 979 | ||
978 | 980 | ||
979 | static int getintsize (lua_State *L, int arg) { | 981 | static int getintsize (lua_State *L, int arg) { |
980 | int size = luaL_optint(L, arg, SZINT); | 982 | int size = luaL_optint(L, arg, 0); |
983 | if (size == 0) size = SZINT; | ||
981 | luaL_argcheck(L, 1 <= size && size <= MAXINTSIZE, arg, | 984 | luaL_argcheck(L, 1 <= size && size <= MAXINTSIZE, arg, |
982 | "integer size out of valid range"); | 985 | "integer size out of valid range"); |
983 | return size; | 986 | return size; |
@@ -1087,9 +1090,10 @@ static void correctendianess (lua_State *L, char *b, int size, int endianarg) { | |||
1087 | (sizeof(lua_Number) == sizeof(float) ? "f" : "d") | 1090 | (sizeof(lua_Number) == sizeof(float) ? "f" : "d") |
1088 | 1091 | ||
1089 | static int getfloatsize (lua_State *L, int arg) { | 1092 | static int getfloatsize (lua_State *L, int arg) { |
1090 | const char *size = luaL_optstring(L, arg, DEFAULTFLOATSIZE); | 1093 | const char *size = luaL_optstring(L, arg, "n"); |
1094 | if (*size == 'n') size = DEFAULTFLOATSIZE; | ||
1091 | luaL_argcheck(L, *size == 'd' || *size == 'f', arg, | 1095 | luaL_argcheck(L, *size == 'd' || *size == 'f', arg, |
1092 | "size must be 'f' or 'd'"); | 1096 | "size must be 'f'/'d'/'n'"); |
1093 | return (*size == 'd' ? sizeof(double) : sizeof(float)); | 1097 | return (*size == 'd' ? sizeof(double) : sizeof(float)); |
1094 | } | 1098 | } |
1095 | 1099 | ||