diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-22 14:15:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-22 14:15:18 -0300 |
commit | 52ee91dd73199e068d31d3ac138d933ddd4fb9b1 (patch) | |
tree | 9f9f1fdc16c8a3464fef14b9946482df688c2ea8 | |
parent | 191fd35f0a6cd47ea03417a663395acf5d0e9bf5 (diff) | |
download | lua-52ee91dd73199e068d31d3ac138d933ddd4fb9b1.tar.gz lua-52ee91dd73199e068d31d3ac138d933ddd4fb9b1.tar.bz2 lua-52ee91dd73199e068d31d3ac138d933ddd4fb9b1.zip |
better encapsulation of some types
-rw-r--r-- | lbaselib.c | 4 | ||||
-rw-r--r-- | ldo.c | 7 | ||||
-rw-r--r-- | liolib.c | 6 | ||||
-rw-r--r-- | llex.c | 6 | ||||
-rw-r--r-- | llimits.h | 12 | ||||
-rw-r--r-- | lobject.c | 4 | ||||
-rw-r--r-- | lstring.c | 4 | ||||
-rw-r--r-- | lstrlib.c | 72 | ||||
-rw-r--r-- | lua.h | 19 | ||||
-rw-r--r-- | lualib.h | 13 |
10 files changed, 83 insertions, 64 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.23 2001/02/09 19:52:24 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.24 2001/02/20 18:29:54 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -100,7 +100,7 @@ static int luaB_tonumber (lua_State *L) { | |||
100 | luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); | 100 | luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range"); |
101 | n = strtoul(s1, &s2, base); | 101 | n = strtoul(s1, &s2, base); |
102 | if (s1 != s2) { /* at least one valid digit? */ | 102 | if (s1 != s2) { /* at least one valid digit? */ |
103 | while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */ | 103 | while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ |
104 | if (*s2 == '\0') { /* no invalid trailing characters? */ | 104 | if (*s2 == '\0') { /* no invalid trailing characters? */ |
105 | lua_pushnumber(L, n); | 105 | lua_pushnumber(L, n); |
106 | return 1; | 106 | return 1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.123 2001/02/07 18:13:49 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.124 2001/02/20 18:15:33 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -265,12 +265,9 @@ static int parse_file (lua_State *L, const char *filename) { | |||
265 | ZIO z; | 265 | ZIO z; |
266 | int status; | 266 | int status; |
267 | int bin; /* flag for file mode */ | 267 | int bin; /* flag for file mode */ |
268 | int c; /* look ahead char */ | ||
269 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | 268 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); |
270 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | 269 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ |
271 | c = fgetc(f); | 270 | bin = (ungetc(fgetc(f), f) == ID_CHUNK); |
272 | ungetc(c, f); | ||
273 | bin = (c == ID_CHUNK); | ||
274 | if (bin && f != stdin) { | 271 | if (bin && f != stdin) { |
275 | fclose(f); | 272 | fclose(f); |
276 | f = fopen(filename, "rb"); /* reopen in binary mode */ | 273 | f = fopen(filename, "rb"); /* reopen in binary mode */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.105 2001/02/09 16:25:50 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.106 2001/02/09 19:52:54 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -214,7 +214,7 @@ static int read_number (lua_State *L, FILE *f) { | |||
214 | 214 | ||
215 | 215 | ||
216 | static int read_word (lua_State *L, FILE *f) { | 216 | static int read_word (lua_State *L, FILE *f) { |
217 | int c; | 217 | l_charint c; |
218 | luaL_Buffer b; | 218 | luaL_Buffer b; |
219 | luaL_buffinit(L, &b); | 219 | luaL_buffinit(L, &b); |
220 | do { c = fgetc(f); } while (isspace(c)); /* skip spaces */ | 220 | do { c = fgetc(f); } while (isspace(c)); /* skip spaces */ |
@@ -273,7 +273,7 @@ static void read_file (lua_State *L, FILE *f) { | |||
273 | 273 | ||
274 | static int read_chars (lua_State *L, FILE *f, size_t n) { | 274 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
275 | if (n == 0) { /* test eof? */ | 275 | if (n == 0) { /* test eof? */ |
276 | int c = fgetc(f); | 276 | l_charint c = fgetc(f); |
277 | ungetc(c, f); | 277 | ungetc(c, f); |
278 | lua_pushlstring(L, NULL, 0); | 278 | lua_pushlstring(L, NULL, 0); |
279 | return (c != EOF); | 279 | return (c != EOF); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.76 2001/01/19 13:20:30 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.77 2001/02/09 20:22:29 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -36,7 +36,7 @@ void luaX_init (lua_State *L) { | |||
36 | for (i=0; i<NUM_RESERVED; i++) { | 36 | for (i=0; i<NUM_RESERVED; i++) { |
37 | TString *ts = luaS_new(L, token2string[i]); | 37 | TString *ts = luaS_new(L, token2string[i]); |
38 | lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); | 38 | lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); |
39 | ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ | 39 | ts->marked = RESERVEDMARK+i; /* reserved word */ |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
@@ -255,7 +255,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
255 | c = 10*c + (LS->current-'0'); | 255 | c = 10*c + (LS->current-'0'); |
256 | next(LS); | 256 | next(LS); |
257 | } while (++i<3 && isdigit(LS->current)); | 257 | } while (++i<3 && isdigit(LS->current)); |
258 | if (c != (unsigned char)c) { | 258 | if (c > UCHAR_MAX) { |
259 | save(L, '\0', l); | 259 | save(L, '\0', l); |
260 | luaX_error(LS, "escape sequence too large", TK_STRING); | 260 | luaX_error(LS, "escape sequence too large", TK_STRING); |
261 | } | 261 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.22 2001/02/09 16:24:44 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.23 2001/02/20 18:15:33 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other "installation-dependent" definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -32,11 +32,17 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | /* function to convert a lua_Number to a string */ | 34 | /* function to convert a lua_Number to a string */ |
35 | #ifndef NUMBER_FMT | ||
35 | #define NUMBER_FMT "%.16g" /* LUA_NUMBER */ | 36 | #define NUMBER_FMT "%.16g" /* LUA_NUMBER */ |
37 | #endif | ||
38 | #ifndef lua_number2str | ||
36 | #define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) | 39 | #define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) |
40 | #endif | ||
37 | 41 | ||
38 | /* function to convert a string to a lua_Number */ | 42 | /* function to convert a string to a lua_Number */ |
43 | #ifndef lua_str2number | ||
39 | #define lua_str2number(s,p) strtod((s), (p)) | 44 | #define lua_str2number(s,p) strtod((s), (p)) |
45 | #endif | ||
40 | 46 | ||
41 | 47 | ||
42 | 48 | ||
@@ -63,6 +69,10 @@ typedef long ls_nstr; | |||
63 | typedef unsigned char lu_byte; | 69 | typedef unsigned char lu_byte; |
64 | 70 | ||
65 | 71 | ||
72 | /* macro to `unsign' a character */ | ||
73 | #define uchar(c) ((unsigned char)(c)) | ||
74 | |||
75 | |||
66 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 76 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
67 | 77 | ||
68 | 78 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.64 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.65 2001/02/20 18:15:33 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -48,7 +48,7 @@ int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */ | |||
48 | char *endptr; | 48 | char *endptr; |
49 | lua_Number res = lua_str2number(s, &endptr); | 49 | lua_Number res = lua_str2number(s, &endptr); |
50 | if (endptr == s) return 0; /* no conversion */ | 50 | if (endptr == s) return 0; /* no conversion */ |
51 | while (isspace((unsigned char)*endptr)) endptr++; | 51 | while (isspace(uchar(*endptr))) endptr++; |
52 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ | 52 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ |
53 | *result = res; | 53 | *result = res; |
54 | return 1; | 54 | return 1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.58 2001/02/09 20:29:33 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.59 2001/02/20 18:15:33 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -69,7 +69,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
70 | size_t l1; | 70 | size_t l1; |
71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
72 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]); | 72 | h = h ^ ((h<<5)+(h>>2)+uchar(str[l1-1])); |
73 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) { | 73 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) { |
74 | if (ts->len == l && (memcmp(str, getstr(ts), l) == 0)) | 74 | if (ts->len == l && (memcmp(str, getstr(ts), l) == 0)) |
75 | return ts; | 75 | return ts; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.61 2001/01/10 16:58:11 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.62 2001/02/02 19:02:40 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 | */ |
@@ -55,7 +55,7 @@ static int str_lower (lua_State *L) { | |||
55 | const char *s = luaL_check_lstr(L, 1, &l); | 55 | const char *s = luaL_check_lstr(L, 1, &l); |
56 | luaL_buffinit(L, &b); | 56 | luaL_buffinit(L, &b); |
57 | for (i=0; i<l; i++) | 57 | for (i=0; i<l; i++) |
58 | luaL_putchar(&b, tolower((unsigned char)(s[i]))); | 58 | luaL_putchar(&b, tolower(uchar(s[i]))); |
59 | luaL_pushresult(&b); | 59 | luaL_pushresult(&b); |
60 | return 1; | 60 | return 1; |
61 | } | 61 | } |
@@ -68,7 +68,7 @@ static int str_upper (lua_State *L) { | |||
68 | const char *s = luaL_check_lstr(L, 1, &l); | 68 | const char *s = luaL_check_lstr(L, 1, &l); |
69 | luaL_buffinit(L, &b); | 69 | luaL_buffinit(L, &b); |
70 | for (i=0; i<l; i++) | 70 | for (i=0; i<l; i++) |
71 | luaL_putchar(&b, toupper((unsigned char)(s[i]))); | 71 | luaL_putchar(&b, toupper(uchar(s[i]))); |
72 | luaL_pushresult(&b); | 72 | luaL_pushresult(&b); |
73 | return 1; | 73 | return 1; |
74 | } | 74 | } |
@@ -91,7 +91,7 @@ static int str_byte (lua_State *L) { | |||
91 | const char *s = luaL_check_lstr(L, 1, &l); | 91 | const char *s = luaL_check_lstr(L, 1, &l); |
92 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); | 92 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); |
93 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); | 93 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); |
94 | lua_pushnumber(L, (unsigned char)s[pos-1]); | 94 | lua_pushnumber(L, uchar(s[pos-1])); |
95 | return 1; | 95 | return 1; |
96 | } | 96 | } |
97 | 97 | ||
@@ -103,8 +103,8 @@ static int str_char (lua_State *L) { | |||
103 | luaL_buffinit(L, &b); | 103 | luaL_buffinit(L, &b); |
104 | for (i=1; i<=n; i++) { | 104 | for (i=1; i<=n; i++) { |
105 | int c = luaL_check_int(L, i); | 105 | int c = luaL_check_int(L, i); |
106 | luaL_arg_check(L, (unsigned char)c == c, i, "invalid value"); | 106 | luaL_arg_check(L, uchar(c) == c, i, "invalid value"); |
107 | luaL_putchar(&b, (unsigned char)c); | 107 | luaL_putchar(&b, uchar(c)); |
108 | } | 108 | } |
109 | luaL_pushresult(&b); | 109 | luaL_pushresult(&b); |
110 | return 1; | 110 | return 1; |
@@ -177,26 +177,26 @@ static const char *luaI_classend (MatchState *ms, const char *p) { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | static int match_class (int c, int cl) { | 180 | static int match_class (char c, char cl) { |
181 | int res; | 181 | int res; |
182 | switch (tolower(cl)) { | 182 | switch (tolower(uchar(cl))) { |
183 | case 'a' : res = isalpha(c); break; | 183 | case 'a' : res = isalpha(uchar(c)); break; |
184 | case 'c' : res = iscntrl(c); break; | 184 | case 'c' : res = iscntrl(uchar(c)); break; |
185 | case 'd' : res = isdigit(c); break; | 185 | case 'd' : res = isdigit(uchar(c)); break; |
186 | case 'l' : res = islower(c); break; | 186 | case 'l' : res = islower(uchar(c)); break; |
187 | case 'p' : res = ispunct(c); break; | 187 | case 'p' : res = ispunct(uchar(c)); break; |
188 | case 's' : res = isspace(c); break; | 188 | case 's' : res = isspace(uchar(c)); break; |
189 | case 'u' : res = isupper(c); break; | 189 | case 'u' : res = isupper(uchar(c)); break; |
190 | case 'w' : res = isalnum(c); break; | 190 | case 'w' : res = isalnum(uchar(c)); break; |
191 | case 'x' : res = isxdigit(c); break; | 191 | case 'x' : res = isxdigit(uchar(c)); break; |
192 | case 'z' : res = (c == '\0'); break; | 192 | case 'z' : res = (c == '\0'); break; |
193 | default: return (cl == c); | 193 | default: return (cl == c); |
194 | } | 194 | } |
195 | return (islower(cl) ? res : !res); | 195 | return (islower(uchar(cl)) ? res : !res); |
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
199 | static int matchbracketclass (int c, const char *p, const char *endclass) { | 199 | static int matchbracketclass (char c, const char *p, const char *endclass) { |
200 | int sig = 1; | 200 | int sig = 1; |
201 | if (*(p+1) == '^') { | 201 | if (*(p+1) == '^') { |
202 | sig = 0; | 202 | sig = 0; |
@@ -205,30 +205,30 @@ static int matchbracketclass (int c, const char *p, const char *endclass) { | |||
205 | while (++p < endclass) { | 205 | while (++p < endclass) { |
206 | if (*p == ESC) { | 206 | if (*p == ESC) { |
207 | p++; | 207 | p++; |
208 | if (match_class(c, (unsigned char)*p)) | 208 | if (match_class(c, *p)) |
209 | return sig; | 209 | return sig; |
210 | } | 210 | } |
211 | else if ((*(p+1) == '-') && (p+2 < endclass)) { | 211 | else if ((*(p+1) == '-') && (p+2 < endclass)) { |
212 | p+=2; | 212 | p+=2; |
213 | if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p) | 213 | if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p)) |
214 | return sig; | 214 | return sig; |
215 | } | 215 | } |
216 | else if ((int)(unsigned char)*p == c) return sig; | 216 | else if (*p == c) return sig; |
217 | } | 217 | } |
218 | return !sig; | 218 | return !sig; |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | static int luaI_singlematch (int c, const char *p, const char *ep) { | 222 | static int luaI_singlematch (char c, const char *p, const char *ep) { |
223 | switch (*p) { | 223 | switch (*p) { |
224 | case '.': /* matches any char */ | 224 | case '.': /* matches any char */ |
225 | return 1; | 225 | return 1; |
226 | case ESC: | 226 | case ESC: |
227 | return match_class(c, (unsigned char)*(p+1)); | 227 | return match_class(c, *(p+1)); |
228 | case '[': | 228 | case '[': |
229 | return matchbracketclass(c, p, ep-1); | 229 | return matchbracketclass(c, p, ep-1); |
230 | default: | 230 | default: |
231 | return ((unsigned char)*p == c); | 231 | return (*p == c); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
@@ -258,7 +258,7 @@ static const char *matchbalance (MatchState *ms, const char *s, const char *p) { | |||
258 | static const char *max_expand (MatchState *ms, const char *s, const char *p, | 258 | static const char *max_expand (MatchState *ms, const char *s, const char *p, |
259 | const char *ep) { | 259 | const char *ep) { |
260 | sint32 i = 0; /* counts maximum expand for item */ | 260 | sint32 i = 0; /* counts maximum expand for item */ |
261 | while ((s+i)<ms->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) | 261 | while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep)) |
262 | i++; | 262 | i++; |
263 | /* keeps trying to match with the maximum repetitions */ | 263 | /* keeps trying to match with the maximum repetitions */ |
264 | while (i>=0) { | 264 | while (i>=0) { |
@@ -276,7 +276,7 @@ static const char *min_expand (MatchState *ms, const char *s, const char *p, | |||
276 | const char *res = match(ms, s, ep+1); | 276 | const char *res = match(ms, s, ep+1); |
277 | if (res != NULL) | 277 | if (res != NULL) |
278 | return res; | 278 | return res; |
279 | else if (s<ms->src_end && luaI_singlematch((unsigned char)*s, p, ep)) | 279 | else if (s<ms->src_end && luaI_singlematch(*s, p, ep)) |
280 | s++; /* try with one more repetition */ | 280 | s++; /* try with one more repetition */ |
281 | else return NULL; | 281 | else return NULL; |
282 | } | 282 | } |
@@ -328,7 +328,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
328 | case ')': /* end capture */ | 328 | case ')': /* end capture */ |
329 | return end_capture(ms, s, p+1); | 329 | return end_capture(ms, s, p+1); |
330 | case ESC: /* may be %[0-9] or %b */ | 330 | case ESC: /* may be %[0-9] or %b */ |
331 | if (isdigit((unsigned char)(*(p+1)))) { /* capture? */ | 331 | if (isdigit(uchar(*(p+1)))) { /* capture? */ |
332 | s = match_capture(ms, s, *(p+1)); | 332 | s = match_capture(ms, s, *(p+1)); |
333 | if (s == NULL) return NULL; | 333 | if (s == NULL) return NULL; |
334 | p+=2; goto init; /* else return match(ms, s, p+2) */ | 334 | p+=2; goto init; /* else return match(ms, s, p+2) */ |
@@ -347,7 +347,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
347 | else goto dflt; | 347 | else goto dflt; |
348 | default: dflt: { /* it is a pattern item */ | 348 | default: dflt: { /* it is a pattern item */ |
349 | const char *ep = luaI_classend(ms, p); /* points to what is next */ | 349 | const char *ep = luaI_classend(ms, p); /* points to what is next */ |
350 | int m = s<ms->src_end && luaI_singlematch((unsigned char)*s, p, ep); | 350 | int m = s<ms->src_end && luaI_singlematch(*s, p, ep); |
351 | switch (*ep) { | 351 | switch (*ep) { |
352 | case '?': { /* optional */ | 352 | case '?': { /* optional */ |
353 | const char *res; | 353 | const char *res; |
@@ -460,7 +460,7 @@ static void add_s (MatchState *ms, luaL_Buffer *b) { | |||
460 | luaL_putchar(b, news[i]); | 460 | luaL_putchar(b, news[i]); |
461 | else { | 461 | else { |
462 | i++; /* skip ESC */ | 462 | i++; /* skip ESC */ |
463 | if (!isdigit((unsigned char)news[i])) | 463 | if (!isdigit(uchar(news[i]))) |
464 | luaL_putchar(b, news[i]); | 464 | luaL_putchar(b, news[i]); |
465 | else { | 465 | else { |
466 | int level = check_capture(ms, news[i]); | 466 | int level = check_capture(ms, news[i]); |
@@ -552,15 +552,15 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form, | |||
552 | int *hasprecision) { | 552 | int *hasprecision) { |
553 | const char *p = strfrmt; | 553 | const char *p = strfrmt; |
554 | while (strchr("-+ #0", *p)) p++; /* skip flags */ | 554 | while (strchr("-+ #0", *p)) p++; /* skip flags */ |
555 | if (isdigit((unsigned char)*p)) p++; /* skip width */ | 555 | if (isdigit(uchar(*p))) p++; /* skip width */ |
556 | if (isdigit((unsigned char)*p)) p++; /* (2 digits at most) */ | 556 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
557 | if (*p == '.') { | 557 | if (*p == '.') { |
558 | p++; | 558 | p++; |
559 | *hasprecision = 1; | 559 | *hasprecision = 1; |
560 | if (isdigit((unsigned char)*p)) p++; /* skip precision */ | 560 | if (isdigit(uchar(*p))) p++; /* skip precision */ |
561 | if (isdigit((unsigned char)*p)) p++; /* (2 digits at most) */ | 561 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
562 | } | 562 | } |
563 | if (isdigit((unsigned char)*p)) | 563 | if (isdigit(uchar(*p))) |
564 | lua_error(L, "invalid format (width or precision too long)"); | 564 | lua_error(L, "invalid format (width or precision too long)"); |
565 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ | 565 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ |
566 | lua_error(L, "invalid format (too long)"); | 566 | lua_error(L, "invalid format (too long)"); |
@@ -585,7 +585,7 @@ static int str_format (lua_State *L) { | |||
585 | char form[MAX_FORMAT]; /* to store the format (`%...') */ | 585 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
586 | char buff[MAX_ITEM]; /* to store the formatted item */ | 586 | char buff[MAX_ITEM]; /* to store the formatted item */ |
587 | int hasprecision = 0; | 587 | int hasprecision = 0; |
588 | if (isdigit((unsigned char)*strfrmt) && *(strfrmt+1) == '$') | 588 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') |
589 | lua_error(L, "obsolete `format' option (d$)"); | 589 | lua_error(L, "obsolete `format' option (d$)"); |
590 | arg++; | 590 | arg++; |
591 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 591 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.86 2001/02/09 19:53:16 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.87 2001/02/20 18:15:33 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
@@ -39,10 +39,6 @@ | |||
39 | #define LUA_MULTRET (-1) | 39 | #define LUA_MULTRET (-1) |
40 | 40 | ||
41 | 41 | ||
42 | /* minimum stack available for a C function */ | ||
43 | #define LUA_MINSTACK 20 | ||
44 | |||
45 | |||
46 | /* error codes for lua_do* */ | 42 | /* error codes for lua_do* */ |
47 | #define LUA_ERRRUN 1 | 43 | #define LUA_ERRRUN 1 |
48 | #define LUA_ERRFILE 2 | 44 | #define LUA_ERRFILE 2 |
@@ -50,10 +46,6 @@ | |||
50 | #define LUA_ERRMEM 4 | 46 | #define LUA_ERRMEM 4 |
51 | #define LUA_ERRERR 5 | 47 | #define LUA_ERRERR 5 |
52 | 48 | ||
53 | |||
54 | /* Lua numerical type */ | ||
55 | typedef double lua_Number; | ||
56 | |||
57 | typedef struct lua_State lua_State; | 49 | typedef struct lua_State lua_State; |
58 | 50 | ||
59 | typedef int (*lua_CFunction) (lua_State *L); | 51 | typedef int (*lua_CFunction) (lua_State *L); |
@@ -71,6 +63,7 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
71 | #define LUA_TFUNCTION 5 | 63 | #define LUA_TFUNCTION 5 |
72 | 64 | ||
73 | 65 | ||
66 | |||
74 | /* | 67 | /* |
75 | ** generic extra include file | 68 | ** generic extra include file |
76 | */ | 69 | */ |
@@ -79,6 +72,14 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
79 | #endif | 72 | #endif |
80 | 73 | ||
81 | 74 | ||
75 | /* minimum stack available for a C function */ | ||
76 | #define LUA_MINSTACK 20 | ||
77 | |||
78 | |||
79 | /* Lua numerical type */ | ||
80 | typedef double lua_Number; | ||
81 | |||
82 | |||
82 | 83 | ||
83 | /* mark for all API functions */ | 84 | /* mark for all API functions */ |
84 | #ifndef LUA_API | 85 | #ifndef LUA_API |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lualib.h,v 1.14 2000/10/27 16:15:53 roberto Exp roberto $ | 2 | ** $Id: lualib.h,v 1.15 2000/11/23 13:49:35 roberto Exp roberto $ |
3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -25,4 +25,15 @@ LUALIB_API void lua_mathlibopen (lua_State *L); | |||
25 | LUALIB_API void lua_dblibopen (lua_State *L); | 25 | LUALIB_API void lua_dblibopen (lua_State *L); |
26 | 26 | ||
27 | 27 | ||
28 | |||
29 | /* | ||
30 | ** `private' part | ||
31 | */ | ||
32 | |||
33 | /* macro to `unsign' a character */ | ||
34 | #define uchar(c) ((unsigned char)(c)) | ||
35 | |||
36 | /* integer type to hold the result of fgetc */ | ||
37 | typedef int l_charint; | ||
38 | |||
28 | #endif | 39 | #endif |