stringstack.lua

colloquy-1.35.30/src/stringstack.lua · 658 B

From the archive colloquy-1.35.30.tar.bz2

Download the archive   « Back to the archive contents

-- simple string stacks for colloquy

stringStack = {
   new = function()
     return {
       add = stringStack.add,
       create = stringStack.create,
       stack = {},
     }
   end,

   add = function(self, string)
     local i;
     tinsert(self.stack, string);
     for i = self.stack.n - 1, 1, -1 do
       if (strlen(self.stack[i]) > strlen(self.stack[i + 1])) then break end;
       self.stack[i] = self.stack[i] .. tremove(self.stack);
     end;
   end,

   create = function(self)
     local i;
     for i = self.stack.n - 1, 1, -1 do
       self.stack[i] = self.stack[i] .. tremove(self.stack);
     end;
     return self.stack[1];
   end,

};

Site Stats

Snippets: 1791
Codebases: 571