Transformando exercício de C# para Lua, ajuda

55 views
Skip to first unread message

flavio...@gmail.com

unread,
Jun 24, 2020, 8:15:12 PM6/24/20
to Lua BR
// Displaying one line of text with multiple statements
using System;

namespace Welcome2
{
    class Welcome2
    {
        static void Main(string[] args)
        {
            Console.Write("Welcome to ");
            Console.WriteLine("C# Programming!");
        }
    }

Saída: -->  Welcome to C# Programming!

Jadson Medeiros

unread,
Jun 25, 2020, 1:03:01 PM6/25/20
to Lua BR
io.write("Welcome to ")
io.write("Lua Programming!")

Arion Deno

unread,
Jun 25, 2020, 1:18:40 PM6/25/20
to lua...@googlegroups.com
Acho muito legal vc fazer isso.



--
Você recebeu essa mensagem porque está inscrito no grupo "Lua BR" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para lua-br+un...@googlegroups.com.
Para ver essa discussão na Web, acesse https://groups.google.com/d/msgid/lua-br/1cedfb1c-a00a-4d3e-9d0a-3edab7180787o%40googlegroups.com.

flavio...@gmail.com

unread,
Jun 25, 2020, 7:32:48 PM6/25/20
to Lua BR
Porque a função PRINT não funciona como a IO.
pela print fica uma frase embaixo da outra. Talvez seja pq não exista PRINTLN em Lua

Denis Dos Santos Silva

unread,
Jun 26, 2020, 9:01:32 AM6/26/20
to Lua BR
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;
}

flavio...@gmail.com

unread,
Jun 26, 2020, 1:16:00 PM6/26/20
to Lua BR
Valeu Obrigado!
Reply all
Reply to author
Forward
0 new messages