olhando a função 'print()' nativa do lua-5.2*
(deve ser mto parecida ou igual as demais versoes) é adicionado um "\n" no fim
exemplos:
>> lua-5.2 -e 'print("abc", "bcd");'
<< abc<tab>bcd<enter>
>> lua-5.2 -e 'io.write("abc", "bcd");'
<< abcbcd
>> lua-5.2 -e 'io.write("Welcome to "); print("Lua Programming!")';
<< Welcome to C# Programming!
OBS: é permitido jogar pra saidas especificas STDOUT, STDERR
io.stdout:write("xxx"); -- stdout
io.write("xxx");
io.stderr:write("xxx"); -- stderr
Alternativamente voce pode escrever suas proprias funcoes
-- << teste.lua >> --
_G.real_print = _G.print;
function print( arg ) io.write(arg); end
function println( arg ) _G.real_print( arg ); end
print('hello ')
println('mundo')
-- << fim >> --
>> $ lua-5.2 teste.lua
<< hello mundo
-- funcao print
lbaselib.c
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getglobal(L, "tostring");
for (i=1; i<=n; i++) {
const char *s;
size_t l;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tolstring(L, -1, &l); /* get result */
if (s == NULL)
return luaL_error(L,
LUA_QL("tostring") " must return a string to " LUA_QL("print"));
if (i>1) luai_writestring("\t", 1);
luai_writestring(s, l);
lua_pop(L, 1); /* pop result */
}
luai_writeline();
return 0;
}