SHOW:
|
|
- or go back to the newest paste.
1 | require 'luanet' | |
2 | --luanet.load_assembly("System") | |
3 | Console = luanet.import_type("System.Console") | |
4 | ConsoleColor = luanet.import_type("System.ConsoleColor") | |
5 | ||
6 | local FILENAME = "fook.txt" | |
7 | ||
8 | function string:split(delimiter, limit) | |
9 | local result = { } | |
10 | local from = 1 | |
11 | local delim_from, delim_to = string.find( self, delimiter, from ) | |
12 | while delim_from do | |
13 | table.insert( result, string.sub( self, from , delim_from-1 ) ) | |
14 | from = delim_to + 1 | |
15 | delim_from, delim_to = string.find( self, delimiter, from ) | |
16 | end | |
17 | table.insert( result, string.sub( self, from ) ) | |
18 | ||
19 | for i=limit+1,#result do | |
20 | result[limit] = result[limit]..delimiter..result[i] | |
21 | end | |
22 | ||
23 | return result | |
24 | end | |
25 | ||
26 | local appendtext = "" | |
27 | Console.ForegroundColor = ConsoleColor.Green --Change colour to pure green | |
28 | while(true) do --infinite loop until "break" | |
29 | f = io.open(FILENAME, "r") | |
30 | os.execute("Cls") --clear screen and print lines | |
31 | for ln in f:lines() do | |
32 | io.write("\n"..ln) | |
33 | end | |
34 | io.write(appendtext) --print() without the new line | |
35 | f:close() --close the file so we can start a writing stream instead of read only | |
36 | print("\n----------------------------") | |
37 | ||
38 | userinput = io.read() | |
39 | local args = userinput:split(" ", 2) | |
40 | local cmd, val = args[1], args[2] | |
41 | f = io.open(FILENAME, "a") | |
42 | if cmd == "save" then | |
43 | f:write(appendtext) --write the appended text to the file, flush, and clear append | |
44 | f:flush() | |
45 | appendtext = "" | |
46 | elseif cmd == "write" then | |
47 | appendtext = appendtext..val --add onto appended text | |
48 | elseif cmd == "return" then | |
49 | appendtext = appendtext.."\n" --start on a new line | |
50 | elseif cmd == "exit" then | |
51 | break --exit the while loop. | |
52 | end | |
53 | f:close() --close writing so that we can read it for next loop | |
54 | end |