I seem to be having some trouble retrieving the value of strings previously stored in a table.
For example, let say I have something like this:
Code: Select all
test = {"String"}
a = string.sub(test[1],1,-1)
print(a)
but when I try it on Love 2D I get an error
or let say I have this other code:
Code: Select all
test = {"index"}
test2 = {}
test2[test[1]] = "text"
print(test2.index)
It also appears that trying to print a string from a table to the console gives out a pointer to the table instead of the actual value.
Code: Select all
test = {"index"}
test2 = {}
test2[test[1]] = "text"
print(test[1])
print(test2.index)
but in love 2D I get this:
My question is. How do I get love 2D to give me the actual string, or at least to get example #2 to work?
Bonus question, I'm writing a simple csv parser for my project, but it looks like love2d doesn't recognize the file handler object from
io.open(). I get this error
Do I have to use Love 2Ds own file reading functions? Or is there something else I'm doing wrong.
This is the code for my parser thus far:
Code: Select all
function loadcsv(path)
local OutTable = {}
local file = io.open(path, "r")
local linecount = 0
for line in file:lines() do
local data = {}
local headers = {}
local headerkey = 1
if linecount < 1 then
for val in line:gmatch("([^,]+),?") do
table.insert(headers, val)
end
else
for word in line:gmatch("([^,]+),?") do
data[headers[headerkey]] = word
headerkey = headerkey + 1
table.insert(OutTable, data)
end
end
linecount = linecount + 1
end
file:close()
return OutTable
end
Code: Select all
PropertyKey1,Propertykey2,Propertykey3
object1property1,object1property2,object1property3
object2property1,object2property2,object2property3
object3property1,object3property2,object3property3
Code: Select all
objects = {
{
PropertyKey1 = object1property1
PropertyKey2 = object1property2
PropertyKey3 = object1property3
}
{
PropertyKey1 = object2property1
PropertyKey2 = object2property2
PropertyKey3 = object2property3
}
{
PropertyKey1 = object3property1
PropertyKey2 = object3property2
PropertyKey3 = object3property3
}
}