@@ -587,22 +587,36 @@ static int addreturn (lua_State *L) {
587587}
588588
589589
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+
590602/*
591603** Read multiple lines until a complete Lua statement or an error not
592604** for an incomplete statement. Start with first line already read in
593605** the stack.
594606*/
595607static int multiline (lua_State * L ) {
608+ size_t len ;
609+ const char * line = lua_tolstring (L , 1 , & len ); /* get first line */
610+ checklocal (line );
596611 for (;;) { /* repeat until gets a complete statement */
597- size_t len ;
598- const char * line = lua_tolstring (L , 1 , & len ); /* get what it has */
599612 int status = luaL_loadbuffer (L , line , len , "=stdin" ); /* try it */
600613 if (!incomplete (L , status ) || !pushline (L , 0 ))
601614 return status ; /* should not or cannot try to add continuation line */
602615 lua_remove (L , -2 ); /* remove error message (from incomplete line) */
603616 lua_pushliteral (L , "\n" ); /* add newline... */
604617 lua_insert (L , -2 ); /* ...between the two lines */
605618 lua_concat (L , 3 ); /* join them */
619+ line = lua_tolstring (L , 1 , & len ); /* get what is has */
606620 }
607621}
608622
0 commit comments