Forum

> > CS2D > Scripts > How i can repair it?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How i can repair it?

7 replies
To the start Previous 1 Next To the start

old How i can repair it?

Steru
User Off Offline

Quote
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

old Re: How i can repair it?

DC
Admin Off Offline

Quote
What's the k in line 28 good for?

It should be just
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.

old Re: How i can repair it?

DC
Admin Off Offline

Quote
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

old Re: How i can repair it?

VADemon
User Off Offline

Quote
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.
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")

old Re: How i can repair it?

Starkkz
Moderator Off Offline

Quote
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:
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview