English How i can repair it?

7 replies
Goto Page
To the start Previous 1 Next To the start
21.06.15 09:22:54 pm
Up
Steru
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function explode(div, str) 
     if (div == '') then return false end
     
     local pos, arr = 0, {}
     
     for st, sp in function() return string.find(str, div, pos, true) end do
          table.insert(arr, string.sub(str, pos, st - 1))
          pos = sp + 1
     end
     
     table.insert(arr, string.sub(str,pos))
     return arr
end

function FileExists(file)
     if(io.open(file, 'r') ~= nil) then
          return true
     else
          return false
     end
end

function lines_from(file)
     if not FileExists(file) then return {} end
     
     local lines = {}
     
     for line,k in io.lines(file, 'r') do
          table.insert(lines, explode("\t", line))
     end
     
     return lines
end


[15:12:26] LUA ERROR: /home/admin script.lua:113: bad argument #1 to '(for generator)' (invalid option)

113 = 28

Before new version it was works ;c
IMG:http://imgupload.pl/images/34120863585969895632.png
21.06.15 09:30:48 pm
Up
DC
Admin
Offline Off
What's the k in line 28 good for?

It should be just
Code:
1
for line in io.lines(file, 'r') do

without the ,k

Or is there any special meaning behind the k? It looks just wrong if you ask me.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
21.06.15 09:35:05 pm
Up
Steru
User
Offline Off
I added k when it doesn't work so next suggestions plz
IMG:http://imgupload.pl/images/34120863585969895632.png
21.06.15 09:36:44 pm
Up
DC
Admin
Offline Off
You added it? Why? It makes no sense
Or maybe LuaJIT just doesn't provide io.lines. I don't know
edited 1×, last 21.06.15 09:37:56 pm
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
21.06.15 09:37:51 pm
Up
Steru
User
Offline Off
ehh ok.. anyway, still same error
IMG:http://imgupload.pl/images/34120863585969895632.png
21.06.15 10:08:38 pm
Up
VADemon
User
Offline Off
Put this into a file in /sys/autorun/
It should output text to console and it worked for me. There's nothing significant I changed.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
function lines_from(file)
    
     local lines = {}
     
     for line,k in io.lines(file, 'r') do
          print(line)
          --table.insert(lines, explode("\t", line))
     end
     
     return lines
end
lines_from("Readme.txt")
21.06.15 10:38:36 pm
Up
Starkkz
Moderator
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
function lines_from(file)
     local lines = {}
     local f = io.open(file, "r")
     for line in f:lines() do
          print("Line: "..line)
          table.insert(lines, explode("\t", line))
     end
     f:close()
     return lines
end

What I actually think that doesn't make sense is this:
Code:
1
io.lines(file, 'r')

Because io.lines has only one argument.
http://www.lua.org/manual/5.1/manual.html#pdf-io.lines

Edit: or user VADemon which seems more reliable.
edited 1×, last 22.06.15 12:54:24 am
lol
21.06.15 10:51:01 pm
Up
Steru
User
Offline Off
It works THX
IMG:http://imgupload.pl/images/34120863585969895632.png
To the start Previous 1 Next To the start