Repeated appends slowing down Lua

Posted by Cage_fire_2000 on Wed 15 Oct 2008 04:24 PM — 4 posts, 17,954 views.

USA #0
At least that's what I think the problem is. In my Paste_As_MUSH plugin, since I converted it to Lua, I just tried encoding something and it ran somewhat slow. I believe it's due to the fact that it goes through each character and appends an escaped version of it to an output string, and from what I read in the PiL guide(under reading files) that makes the garbage collector run wild because each time you append it throws out the old string. So for a string 500 characters long, it might throw out 500 strings. Is there any more efficient way of appending?

Edit: I tried posting my plugin but it's too long. I'll link to my website's copy. http://geocities.com/cage_fire_2000/Paste_As_MUSH.xml
Amended on Wed 15 Oct 2008 04:33 PM by Cage_fire_2000
USA #1
Hmm, never mind, this table.concat() looks promising.
USA #2
Check this out:

http://www.lua.org/notes/ltn009.html

USA #3
Alright, thanks for the link, but that seems like a rather complicated solution, and I don't have time to decypher it, I just converted it to use table.insert() instead of appending a string, and at the end used table.concat() it's much better now. I've uploaded version 1.2 to my website.