Capture a whole block of text

Geyser is an object oriented framework for creating, updating and organizing GUI elements within Mudlet.
User avatar
Posts: 649
Joined: Sat Dec 05, 2009 3:19 pm

Re: Capture a whole block of text

Post by demonnic »

In general, once something no longer has a reference to it the garbage collection should clean it out on its next run. That's the main difference between languages ike Lua, Java, and Ruby and those like C. You essentially exchange some temporary bloat for not having to specifically free up the memory you're using. The interpretor occasionally goes through, notes all the reachable objects (those with references(variables) assigned to them) and sweeps away the rest.

also, yeah... your small table of strings is probably not going to tax your RAM any time soon. Especially since Lua will dutifully come behind you and quietly discard the old object for you. =)

Posts: 16
Joined: Wed Oct 23, 2013 6:27 pm

Re: Capture a whole block of text

Post by branden7 »

Ok cool..I dont know a lot about garbage collection so that helps.

I ended up actually using that code in a few places so I turned it into a function and took your advice and got rid of the iterator to wipe out the table.

I set up a global variable script so you wont see where i initialize the vars for this, but this is the scrip file.
Code: [show] | [select all] lua
-- These will capture and display blocks of text                                                 --
-- call capture() within a tempTriggerTimer named captureTempTrigger and pass a GUI block        --
--     IE: capture(GUI.Box6)                                                                     --

function capture(displayBox)
 if (string.find(line, "[a-z]") == nil) and (counter > 2) then
    captureTempTrigger = nil
	 formatAndDisplay(displayBox)  --ok, we are done collecting data. Call this to display it 
    counter = 0 --reset counter
    displayTable = {} --reset the table
 end                  --end if
counter = counter + 1  --cant seem to find a better way to increment
table.insert(displayTable, line)

function formatAndDisplay(displayBox)
output = table.concat(displayTable, "<br>")
clearWindow("displayBox");       --can not figure out how to get this to work. maybe not important, but i like to start fresh
displayBox:echo("<pre>" .. output);  
Seems to work smoother. I also changed the call to work on a soon as it sees the first line of the header for whatever i want to display it fires the tempTriggerTimer.

I occasionally get a little garbage, but I think maybe it's either from not clearing the window first (which i cant make work) or just from the way the actual MUD lags and occasionally displays things wrong.

Post Reply