Page 3 of 3
Re: Multiple threads from one file?
Posted: Mon Aug 08, 2011 7:41 pm
by Astusvis
Here's the thread code, to save a back and forth of questions.
Re: Multiple threads from one file?
Posted: Mon Aug 08, 2011 8:57 pm
by Boolsheet
TSerial is probably not the right thing to use if you have huge tables. As I said, use table.concat.
Code: Select all
local t = {2,4,6,72,34,5,6,43,6,63,32}
local s = table.concat(t, ",") --> "2,4,6,72,34,5,6,43,6,63,32"
Then again it's unusual that it hits the memory limit in this way. Try garbage collecting every other line. :/
Re: Multiple threads from one file?
Posted: Mon Aug 08, 2011 9:02 pm
by Astusvis
Wait, what?
I think you think I know what your talking about.
What is that first piece of code?
And how would I "un-concat" the string?
Re: Multiple threads from one file?
Posted: Mon Aug 08, 2011 9:15 pm
by slime
Code: Select all
local t = {}
for v in str:gmatch("[^,]+") do table.insert(t, v) end
or
Code: Select all
local t = {}
local function insert(v) table.insert(t, v) end
str:gsub("[^,]+", insert)
Re: Multiple threads from one file?
Posted: Mon Aug 08, 2011 9:17 pm
by Boolsheet
The code is from TSerial.lua.
You can use the output of table.concat to create a string that is loadable with loadstring.
Code: Select all
local original = {2,4,6,72,34,5,6,43,6,63,32}
local str = "return {".. table.concat(t, ",") .."}"
local copy = loadstring(str)()
It still wastes memory and could be optimized to.
Code: Select all
local original = {"return { [0]=nil", 2,4,6,72,34,5,6,43,6,63,32, "}"} -- Assuming we don't use the index 0.
local str = table.concat(t, ",")
local copy = loadstring(str)()
Lookup
loadstring if you want to know what exactly it does.
(Code is untested)