How do I clear the console in a Lua Program

本秂侑毒 提交于 2019-12-04 20:35:33

问题


I'm making my first Lua program with the console, and I need to find out how to remove all the text in the console without just appending a ton of \n's.


回答1:


You can use os.execute().

On Windows:

os.execute("cls")

On Unix:

os.execute("clear")



回答2:


If your console understands ANSI terminal escape sequences, try io.write("\027[H\027[2J").




回答3:


As mentioned in the other reply, you can use os.execute() to clear the console. However, if you do not have access to this function, then you might be forced to spam the console with new lines, so it seems "empty" to the user.

However, if you are able to use os.execute, then you should definitely use it.

for i = 1, 255 do
    print()
end



回答4:


Sorry for the late answer, but if anyone check this post here's a way to do it :

if not os.execute("clear") then
    os.execute("cls")
elseif not os.execute("cls") then
    for i = 1,25 do
        print("\n\n")
    end
end

This will work on any os.



来源:https://stackoverflow.com/questions/23187310/how-do-i-clear-the-console-in-a-lua-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!