diff options
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -587,15 +587,28 @@ static int addreturn (lua_State *L) { | |||
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | static void checklocal (const char *line) { | ||
591 | static const size_t szloc = sizeof("local") - 1; | ||
592 | static const char space[] = " \t"; | ||
593 | line += strspn(line, space); /* skip spaces */ | ||
594 | if (strncmp(line, "local", szloc) == 0 && /* "local"? */ | ||
595 | strchr(space, *(line + szloc)) != NULL) { /* followed by a space? */ | ||
596 | lua_writestringerror("%s\n", | ||
597 | "warning: locals do not survive across lines in interactive mode"); | ||
598 | } | ||
599 | } | ||
600 | |||
601 | |||
590 | /* | 602 | /* |
591 | ** Read multiple lines until a complete Lua statement or an error not | 603 | ** Read multiple lines until a complete Lua statement or an error not |
592 | ** for an incomplete statement. Start with first line already read in | 604 | ** for an incomplete statement. Start with first line already read in |
593 | ** the stack. | 605 | ** the stack. |
594 | */ | 606 | */ |
595 | static int multiline (lua_State *L) { | 607 | static int multiline (lua_State *L) { |
608 | size_t len; | ||
609 | const char *line = lua_tolstring(L, 1, &len); /* get first line */ | ||
610 | checklocal(line); | ||
596 | for (;;) { /* repeat until gets a complete statement */ | 611 | for (;;) { /* repeat until gets a complete statement */ |
597 | size_t len; | ||
598 | const char *line = lua_tolstring(L, 1, &len); /* get what it has */ | ||
599 | int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */ | 612 | int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */ |
600 | if (!incomplete(L, status) || !pushline(L, 0)) | 613 | if (!incomplete(L, status) || !pushline(L, 0)) |
601 | return status; /* should not or cannot try to add continuation line */ | 614 | return status; /* should not or cannot try to add continuation line */ |
@@ -603,6 +616,7 @@ static int multiline (lua_State *L) { | |||
603 | lua_pushliteral(L, "\n"); /* add newline... */ | 616 | lua_pushliteral(L, "\n"); /* add newline... */ |
604 | lua_insert(L, -2); /* ...between the two lines */ | 617 | lua_insert(L, -2); /* ...between the two lines */ |
605 | lua_concat(L, 3); /* join them */ | 618 | lua_concat(L, 3); /* join them */ |
619 | line = lua_tolstring(L, 1, &len); /* get what is has */ | ||
606 | } | 620 | } |
607 | } | 621 | } |
608 | 622 | ||