Pruebas de lua que no funcionan

estaba haciendo pruebas en lua e intentaba hacer una prueba con luajit. y bueno, me sale el siguiente problema:
luajit: pruebatui.lua:24: ‘’ expected near ‘-’
¿que le puedo hacer?

Hmn… Probablemente ese es un error de código… Deberías pasar la línea de código…

1 me gusta

– configurar la terminal para leer teclas sin esperar Enter
os.execute(“stty -icanon -echo”) – Modo raw (sin buffer/echo)

– Variables de estado
local tareas = {
{texto = “Estudiar carlos”, completada = false},
{texto = “Estudiar lua”, completada = false},
{texto = “Estudiar c”, completada = false},
{texto = “Jugar hackroms”, completada = true}
}
local seleccion = 1
local ejecutado = true
local modo_edicion = false
local texto_edicion = “”

– Funciones de utilidad
local function limpiarPantalla()
io.write(“\27[2J\27[H”) – Limpiar y mover cursor a (1,1)
end

local function dibujarBorde()
io.write(“\27[34m”) – Color azul
print(“+” … string.rep(“-”, 50) … “+”)
for - = 1, 20 do
print(“|” … string.rep(" “, 50) … “|”)
end
print(”+" … string.rep(“-”, 50) … “+”)
io.write("\27[0m]) – Resetear color
end

local function leerTecla()
local char = io.read(1)
if char == “\27” then – Secuencia de escape
char = io.read(2)
if char == “[A” then return “ARRIBA” end
if char == “[B” then return “ABAJO” end
end
if char == “\n” then return “ENTER” end
return char:upper()
end

local function dibujarTareas()
for i, tarea in ipairs(tareas) do
io.write(“\27[” … (i + 2) … “;3H”) – Posicionar cursor
if i == seleccion then
io.write(“\27[47\27[30m”) – Fondo blanco, texto negro
end

  local estado = tarea.completada and "[X]" or "[ ]"
  print(string.format("%s %s", estado, tarea.texto))

  io.write("\27[0m") -- Resetear color
  end

end

local function dibujarInterfaz()
limpiarPantalla()
dibujarBorde()
dibujarTareas()
io.write(“\27[22;3H”) – Barra inferior
print(“Q: Salir | A: Nueva tarea | ENTER: Completar”)
end

– 4. Bucle principal
while ejecutando do
dibujarInterfaz()

  local tecla = leerTecla()

  if tecla == "Q" then
  	 ejecutando = false	 
  elseif tecla == "ARRIBA" and seleccion > 1 then
  	     seleccion = seleccion - 1
  elseif tecla == "ABAJO" and seleccion < #tareas then
  	     seleccion = seleccion +1
  elseif tecla == "ENTER" then
  	     tareas[seleccion].completada = not tareas[seleccion].completada
  elseif tecla == "A" then
  	     io.write("\27[22;3H\27[K") -- Limpiar línea
     io.write("Nueva tarea: ")
     texto_edicion = io.read("*l")
     if texto_edicion ~= "" then
     	table.insert(tareas, {texto = texto_edicion, completada = false})
         end
  end

end

– 5. Restaurar terminal al salir
os.execute(“stty icanon echo”)

Los comentarios en Lua se hacen con -- y no con -, si no se confunde…

Si quieres por si acaso hacer comentarios multilínea, debes usar --[...]… por ejemplo

print("esto es código") -- comentario simple

--[
Esto es un comentario
de varias líneas.
]

PD esto lo escribo con el celular en el colegio xD

1 me gusta