44 posts
Posted 15 August 2016 - 08:57 PM
Very simple code, big-butt error:
table.concat(stack, ",")
That code should concatenate the table into a string with values seperated by a comma.
But then, I get this error:
bad argument: string expected, got table
I made sure stack was a table but that can't be the error since the only string argument it needs
is actually a string.
Edited on 16 August 2016 - 05:30 PM
8543 posts
Posted 15 August 2016 - 09:02 PM
What are the contents of the stack table?
44 posts
Posted 15 August 2016 - 09:23 PM
stack is supposed to have another table at index 1, but I can't test it if table.concat does not work.
44 posts
Posted 15 August 2016 - 09:33 PM
something to add: I even tried doing table.concat on the table that was supposed to be at index 1 before it was inserted.
It gave the same error.
3057 posts
Location
United States of America
Posted 16 August 2016 - 12:23 AM
Ah, I see what is happening. table.concat works on tables of strings. Tables of other types, including tables don't work, and result in an error.
It is possible you want the textutils.serialize function, which takes a table and turns it (and it's contents) into a string.
Edited on 15 August 2016 - 10:23 PM
44 posts
Posted 16 August 2016 - 06:35 AM
Thank you, will do!
1 question, any way to serialize without indentation and all prettifier stuff?
218 posts
Location
tmpim
Posted 16 August 2016 - 06:49 AM
Thank you, will do!
1 question, any way to serialize without indentation and all prettifier stuff?
You could just remove all whitespace and newlines with a gsub, that would get rid of most of it (if not all)
local str = " { \n test = \"example\", \n example = \"test\" }"
local newString = string.gsub(str, "[%s\n]", "")
-- newString == {test="example",example="test"}
Edited on 16 August 2016 - 04:50 AM
44 posts
Posted 16 August 2016 - 06:59 AM
what if the table contents have whitespace, though?
3057 posts
Location
United States of America
Posted 16 August 2016 - 01:14 PM
Don't gsub the table, use
textutils.serialize before the fancy stuff was added.
218 posts
Location
tmpim
Posted 17 August 2016 - 01:14 AM
Don't gsub the table, use
textutils.serialize before the fancy stuff was added.
I meant after it was serialized because textutils.serialize pretty prints the table.
As to the issue of whitespace in the values, don't gsub, just rewrite table.serialize and take out the parts that print whitespace.
3057 posts
Location
United States of America
Posted 17 August 2016 - 01:32 AM
I meant after it was serialized because textutils.serialize pretty prints the table.
As to the issue of whitespace in the values, don't gsub, just rewrite table.serialize and take out the parts that print whitespace.
I linked a version of serialize which doesn't add whitespace in my previous post.
218 posts
Location
tmpim
Posted 17 August 2016 - 05:31 PM
I meant after it was serialized because textutils.serialize pretty prints the table.
As to the issue of whitespace in the values, don't gsub, just rewrite table.serialize and take out the parts that print whitespace.
I linked a version of serialize which doesn't add whitespace in my previous post.
Ah, I assumed it was a link to the wiki xD