How to clear the console in Lua

I am making my first Lua program with a console, and I need to figure out how to remove all the text in the console without adding a ton \ n.

+6
source share
4 answers

You can use os.execute() .

On Windows:

 os.execute("cls") 

On Unix:

 os.execute("clear") 
+7
source

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

+5
source

As mentioned in another answer, you can use os.execute () to clear the console. However, if you do not have access to this function, you may be forced to spam the console with new lines, so the user may look "empty".

However, if you can use os.execute, you should definitely use it.

 for i = 1, 255 do print() end 
+2
source

Sorry for the late reply, but if anyone checks out this post here, this can be done:

 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 with any os.

+1
source

All Articles