diff options
author | Li Jin <dragon-fly@qq.com> | 2020-07-18 16:45:50 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-07-18 16:45:50 +0800 |
commit | 8c596dc1efa8a1267c222b168a4de9c8ba254760 (patch) | |
tree | 699c748e101a48ae267b5f7b19adbfea15f3934e /src/lua/lobject.c | |
parent | 8ab0038c09a79fa8401bb10b7a31d03ef5380417 (diff) | |
download | yuescript-8c596dc1efa8a1267c222b168a4de9c8ba254760.tar.gz yuescript-8c596dc1efa8a1267c222b168a4de9c8ba254760.tar.bz2 yuescript-8c596dc1efa8a1267c222b168a4de9c8ba254760.zip |
fix issue for using return statement with export.
Diffstat (limited to 'src/lua/lobject.c')
-rw-r--r-- | src/lua/lobject.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/lua/lobject.c b/src/lua/lobject.c index b4efae4..f8ea917 100644 --- a/src/lua/lobject.c +++ b/src/lua/lobject.c | |||
@@ -215,37 +215,42 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
215 | /* }====================================================== */ | 215 | /* }====================================================== */ |
216 | 216 | ||
217 | 217 | ||
218 | /* maximum length of a numeral */ | 218 | /* maximum length of a numeral to be converted to a number */ |
219 | #if !defined (L_MAXLENNUM) | 219 | #if !defined (L_MAXLENNUM) |
220 | #define L_MAXLENNUM 200 | 220 | #define L_MAXLENNUM 200 |
221 | #endif | 221 | #endif |
222 | 222 | ||
223 | /* | ||
224 | ** Convert string 's' to a Lua number (put in 'result'). Return NULL on | ||
225 | ** fail or the address of the ending '\0' on success. ('mode' == 'x') | ||
226 | ** means a hexadecimal numeral. | ||
227 | */ | ||
223 | static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { | 228 | static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { |
224 | char *endptr; | 229 | char *endptr; |
225 | *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ | 230 | *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ |
226 | : lua_str2number(s, &endptr); | 231 | : lua_str2number(s, &endptr); |
227 | if (endptr == s) return NULL; /* nothing recognized? */ | 232 | if (endptr == s) return NULL; /* nothing recognized? */ |
228 | while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ | 233 | while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ |
229 | return (*endptr == '\0') ? endptr : NULL; /* OK if no trailing characters */ | 234 | return (*endptr == '\0') ? endptr : NULL; /* OK iff no trailing chars */ |
230 | } | 235 | } |
231 | 236 | ||
232 | 237 | ||
233 | /* | 238 | /* |
234 | ** Convert string 's' to a Lua number (put in 'result'). Return NULL | 239 | ** Convert string 's' to a Lua number (put in 'result') handling the |
235 | ** on fail or the address of the ending '\0' on success. | 240 | ** current locale. |
236 | ** 'pmode' points to (and 'mode' contains) special things in the string: | ||
237 | ** - 'x'/'X' means a hexadecimal numeral | ||
238 | ** - 'n'/'N' means 'inf' or 'nan' (which should be rejected) | ||
239 | ** - '.' just optimizes the search for the common case (nothing special) | ||
240 | ** This function accepts both the current locale or a dot as the radix | 241 | ** This function accepts both the current locale or a dot as the radix |
241 | ** mark. If the conversion fails, it may mean number has a dot but | 242 | ** mark. If the conversion fails, it may mean number has a dot but |
242 | ** locale accepts something else. In that case, the code copies 's' | 243 | ** locale accepts something else. In that case, the code copies 's' |
243 | ** to a buffer (because 's' is read-only), changes the dot to the | 244 | ** to a buffer (because 's' is read-only), changes the dot to the |
244 | ** current locale radix mark, and tries to convert again. | 245 | ** current locale radix mark, and tries to convert again. |
246 | ** The variable 'mode' checks for special characters in the string: | ||
247 | ** - 'n' means 'inf' or 'nan' (which should be rejected) | ||
248 | ** - 'x' means a hexadecimal numeral | ||
249 | ** - '.' just optimizes the search for the common case (no special chars) | ||
245 | */ | 250 | */ |
246 | static const char *l_str2d (const char *s, lua_Number *result) { | 251 | static const char *l_str2d (const char *s, lua_Number *result) { |
247 | const char *endptr; | 252 | const char *endptr; |
248 | const char *pmode = strpbrk(s, ".xXnN"); | 253 | const char *pmode = strpbrk(s, ".xXnN"); /* look for special chars */ |
249 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; | 254 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; |
250 | if (mode == 'n') /* reject 'inf' and 'nan' */ | 255 | if (mode == 'n') /* reject 'inf' and 'nan' */ |
251 | return NULL; | 256 | return NULL; |
@@ -333,8 +338,15 @@ int luaO_utf8esc (char *buff, unsigned long x) { | |||
333 | } | 338 | } |
334 | 339 | ||
335 | 340 | ||
336 | /* maximum length of the conversion of a number to a string */ | 341 | /* |
337 | #define MAXNUMBER2STR 50 | 342 | ** Maximum length of the conversion of a number to a string. Must be |
343 | ** enough to accommodate both LUA_INTEGER_FMT and LUA_NUMBER_FMT. | ||
344 | ** (For a long long int, this is 19 digits plus a sign and a final '\0', | ||
345 | ** adding to 21. For a long double, it can go to a sign, 33 digits, | ||
346 | ** the dot, an exponent letter, an exponent sign, 5 exponent digits, | ||
347 | ** and a final '\0', adding to 43.) | ||
348 | */ | ||
349 | #define MAXNUMBER2STR 44 | ||
338 | 350 | ||
339 | 351 | ||
340 | /* | 352 | /* |
@@ -375,7 +387,7 @@ void luaO_tostring (lua_State *L, TValue *obj) { | |||
375 | */ | 387 | */ |
376 | 388 | ||
377 | /* size for buffer space used by 'luaO_pushvfstring' */ | 389 | /* size for buffer space used by 'luaO_pushvfstring' */ |
378 | #define BUFVFS 400 | 390 | #define BUFVFS 200 |
379 | 391 | ||
380 | /* buffer used by 'luaO_pushvfstring' */ | 392 | /* buffer used by 'luaO_pushvfstring' */ |
381 | typedef struct BuffFS { | 393 | typedef struct BuffFS { |
@@ -387,18 +399,16 @@ typedef struct BuffFS { | |||
387 | 399 | ||
388 | 400 | ||
389 | /* | 401 | /* |
390 | ** Push given string to the stack, as part of the buffer. If the stack | 402 | ** Push given string to the stack, as part of the buffer, and |
391 | ** is almost full, join all partial strings in the stack into one. | 403 | ** join the partial strings in the stack into one. |
392 | */ | 404 | */ |
393 | static void pushstr (BuffFS *buff, const char *str, size_t l) { | 405 | static void pushstr (BuffFS *buff, const char *str, size_t l) { |
394 | lua_State *L = buff->L; | 406 | lua_State *L = buff->L; |
395 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); | 407 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); |
396 | L->top++; /* may use one extra slot */ | 408 | L->top++; /* may use one extra slot */ |
397 | buff->pushed++; | 409 | buff->pushed++; |
398 | if (buff->pushed > 1 && L->top + 1 >= L->stack_last) { | 410 | luaV_concat(L, buff->pushed); /* join partial results into one */ |
399 | luaV_concat(L, buff->pushed); /* join all partial results into one */ | 411 | buff->pushed = 1; |
400 | buff->pushed = 1; | ||
401 | } | ||
402 | } | 412 | } |
403 | 413 | ||
404 | 414 | ||
@@ -521,8 +531,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
521 | } | 531 | } |
522 | addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ | 532 | addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ |
523 | clearbuff(&buff); /* empty buffer into the stack */ | 533 | clearbuff(&buff); /* empty buffer into the stack */ |
524 | if (buff.pushed > 1) | 534 | lua_assert(buff.pushed == 1); |
525 | luaV_concat(L, buff.pushed); /* join all partial results */ | ||
526 | return svalue(s2v(L->top - 1)); | 535 | return svalue(s2v(L->top - 1)); |
527 | } | 536 | } |
528 | 537 | ||