@@ -587,22 +587,36 @@ 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
603
** Read multiple lines until a complete Lua statement or an error not
592
604
** for an incomplete statement. Start with first line already read in
593
605
** the stack.
594
606
*/
595
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
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
612
int status = luaL_loadbuffer (L , line , len , "=stdin" ); /* try it */
600
613
if (!incomplete (L , status ) || !pushline (L , 0 ))
601
614
return status ; /* should not or cannot try to add continuation line */
602
615
lua_remove (L , -2 ); /* remove error message (from incomplete line) */
603
616
lua_pushliteral (L , "\n" ); /* add newline... */
604
617
lua_insert (L , -2 ); /* ...between the two lines */
605
618
lua_concat (L , 3 ); /* join them */
619
+ line = lua_tolstring (L , 1 , & len ); /* get what is has */
606
620
}
607
621
}
608
622
0 commit comments