aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-05-26 13:09:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-05-26 13:09:40 -0300
commitee7d0c26493e1303a06f45b28ee2822c5a6aff05 (patch)
tree86781476f7f308055fc6340440fad855d2ae8601
parentaa13c591f59f55ea31c14fcc554f8fc96dff67c2 (diff)
downloadlua-ee7d0c26493e1303a06f45b28ee2822c5a6aff05.tar.gz
lua-ee7d0c26493e1303a06f45b28ee2822c5a6aff05.tar.bz2
lua-ee7d0c26493e1303a06f45b28ee2822c5a6aff05.zip
new macro 'luai_writeline' to print newlines (and flush 'stdout')
-rw-r--r--lbaselib.c8
-rw-r--r--lua.c7
-rw-r--r--luaconf.h5
3 files changed, 11 insertions, 9 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 67edd96e..eb06df4e 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.259 2011/01/26 16:30:02 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.260 2011/02/28 17:32:10 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*/
@@ -32,13 +32,13 @@ static int luaB_print (lua_State *L) {
32 lua_call(L, 1, 1); 32 lua_call(L, 1, 1);
33 s = lua_tolstring(L, -1, &l); /* get result */ 33 s = lua_tolstring(L, -1, &l); /* get result */
34 if (s == NULL) 34 if (s == NULL)
35 return luaL_error(L, LUA_QL("tostring") " must return a string to " 35 return luaL_error(L,
36 LUA_QL("print")); 36 LUA_QL("tostring") " must return a string to " LUA_QL("print"));
37 if (i>1) luai_writestring("\t", 1); 37 if (i>1) luai_writestring("\t", 1);
38 luai_writestring(s, l); 38 luai_writestring(s, l);
39 lua_pop(L, 1); /* pop result */ 39 lua_pop(L, 1); /* pop result */
40 } 40 }
41 luai_writestring("\n", 1); 41 luai_writeline();
42 return 0; 42 return 0;
43} 43}
44 44
diff --git a/lua.c b/lua.c
index 46783fc2..5b582824 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.197 2011/03/14 15:39:42 roberto Exp roberto $ 2** $Id: lua.c,v 1.198 2011/05/03 16:01:57 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -183,7 +183,8 @@ static int docall (lua_State *L, int narg, int nres) {
183 183
184 184
185static void print_version (void) { 185static void print_version (void) {
186 luai_writestring(LUA_COPYRIGHT "\n", sizeof(LUA_COPYRIGHT) + 1); 186 luai_writestring(LUA_COPYRIGHT, sizeof(LUA_COPYRIGHT));
187 luai_writeline();
187} 188}
188 189
189 190
@@ -320,7 +321,7 @@ static void dotty (lua_State *L) {
320 } 321 }
321 } 322 }
322 lua_settop(L, 0); /* clear stack */ 323 lua_settop(L, 0); /* clear stack */
323 luai_writestring("\n", 1); 324 luai_writeline();
324 progname = oldprogname; 325 progname = oldprogname;
325} 326}
326 327
diff --git a/luaconf.h b/luaconf.h
index f95f93f9..202655ba 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.156 2011/04/20 18:25:54 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.157 2011/04/29 13:56:28 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -209,10 +209,11 @@
209 209
210 210
211/* 211/*
212@@ luai_writestring defines how 'print' prints its results. 212@@ luai_writestring/luai_writeline define how 'print' prints its results.
213*/ 213*/
214#include <stdio.h> 214#include <stdio.h>
215#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) 215#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
216#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
216 217
217/* 218/*
218@@ luai_writestringerror defines how to print error messages. 219@@ luai_writestringerror defines how to print error messages.