[solved, stupid programmer me]<eof> error - string.gmatch()
Posted: Fri Mar 30, 2012 7:31 am
Since I couldn't find a lua function equivalent to java's string.split(), which splits a string around a given string or character (actually regular expression which seems to be about equal to lua's patterns) and returns a table of the values, I decided to try making my own. Looking around the Lua reference manual, I found a function called string.gmatch() that seemed to suit my needs, and I wrote a little function to split a string into only alphanumeric strings (according to the pattern I gave).
(That's actually the whole love file)
The problem is, when I run it I get an error
Code: Select all
[b]function splitstring(string)
local return_table
for val in string.gmatch(string,"%w+") do
table.insert(return_table,val)
end
return return_table
end[/b]
love.load()
stringtable = splitstring("stat;354;332;0.6;0;stalactite_01")
end
love.draw()
for n=0,#stringtable,1 do
love.graphics.print(stringtable[n],32,32+n*32,0,1,1)
end
end
The problem is, when I run it I get an error
Code: Select all
Syntax error: main.lua:11: '<eof>' expected near 'end'