Posted 17 August 2012 - 05:32 PM
Hello everyone!
I made a string split function (based on a function from lua-users.org) that seems to give a very strange result.
Here is the code:
In minecraft (tekkit) this gives the output:
But since I'm a Linux user, I can easily run this on my own computer, but it throws a different (but correct!) result.
I don't know where the fault lies, so maybe you can help me.
Details:
Tekkit 1.2.5 (SMP)
Linux lua version: 5.1.5-2
I made a string split function (based on a function from lua-users.org) that seems to give a very strange result.
Here is the code:
local function strsplit(regex, string, times)
local tab = {}
local startt = 1
local positie, eindpos = string.find(string, regex, startt)
if not times then
times = 0
end
local i = 1
while times == 0 or (positie and i <= times) do
if not positie then
break
end
table.insert(tab, string.sub(string, startt, positie-1))
startt = eindpos + 1
positie, eindpos = string.find(string, regex, startt)
i = i+1
end
table.insert(tab, string.sub(string, startt, -1))
return(tab)
end
local test = "apple 1\npear 2\nbanana 3"
local table = {}
table = strsplit("\n",test,3)
table[1] = strsplit(" ",table[1],1)
table[2] = strsplit(" ",table[2],1)
table[3] = strsplit(" ",table[3],1)
print(table[1][1] .. "---" .. table[1][2])
print("---")
print(table[2][1] .. "---" .. table[2][2])
print("---")
print(table[3][1] .. "---" .. table[3][2])
print("---")
In minecraft (tekkit) this gives the output:
apple---1
---
pear 2---
---
banana 3---
---
So I thought, there must be something wrong with the function.But since I'm a Linux user, I can easily run this on my own computer, but it throws a different (but correct!) result.
$ lua strsplit
apple---1
---
pear---2
---
banana---3
---
I don't know where the fault lies, so maybe you can help me.
Details:
Tekkit 1.2.5 (SMP)
Linux lua version: 5.1.5-2