Multiple threads from one file?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post by Astusvis »

Here's the thread code, to save a back and forth of questions.
Attachments
genimage.lua
CODE!
(1.29 KiB) Downloaded 112 times
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Multiple threads from one file?

Post by Boolsheet »

Code: Select all

s = s..k.."="..v..","
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. :/
Shallow indentations.
User avatar
Astusvis
Prole
Posts: 33
Joined: Fri Aug 05, 2011 5:22 pm

Re: Multiple threads from one file?

Post 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?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Multiple threads from one file?

Post 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)
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Multiple threads from one file?

Post 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)
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 11 guests