Forum

> > CS2D > Scripts > How i can repair it?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How i can repair it?

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How i can repair it?

Steru
User Off Offline

Zitieren
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

alt Re: How i can repair it?

DC
Admin Off Offline

Zitieren
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.

alt Re: How i can repair it?

DC
Admin Off Offline

Zitieren
You added it? Why? It makes no sense
Or maybe LuaJIT just doesn't provide io.lines. I don't know
1× editiert, zuletzt 21.06.15 21:37:56

alt Re: How i can repair it?

VADemon
User Off Offline

Zitieren
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")

alt Re: How i can repair it?

Starkkz
Moderator Off Offline

Zitieren
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.
1× editiert, zuletzt 22.06.15 00:54:24
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht