require 'luanet'
--luanet.load_assembly("System")
Console = luanet.import_type("System.Console")
ConsoleColor = luanet.import_type("System.ConsoleColor")
local FILENAME = "fook.txt"
function string:split(delimiter, limit)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
for i=limit+1,#result do
result[limit] = result[limit]..delimiter..result[i]
end
return result
end
local appendtext = ""
Console.ForegroundColor = ConsoleColor.Green --Change colour to pure green
while(true) do --infinite loop until "break"
f = io.open(FILENAME, "r")
os.execute("Cls") --clear screen and print lines
for ln in f:lines() do
io.write("\n"..ln)
end
io.write(appendtext) --print() without the new line
f:close() --close the file so we can start a writing stream instead of read only
print("\n----------------------------")
userinput = io.read()
local args = userinput:split(" ", 2)
local cmd, val = args[1], args[2]
f = io.open(FILENAME, "a")
if cmd == "save" then
f:write(appendtext) --write the appended text to the file, flush, and clear append
f:flush()
appendtext = ""
elseif cmd == "write" then
appendtext = appendtext..val --add onto appended text
elseif cmd == "return" then
appendtext = appendtext.."\n" --start on a new line
elseif cmd == "exit" then
break --exit the while loop.
end
f:close() --close writing so that we can read it for next loop
end
Comments