S Ferguson
January 20th, 2013, 04:36
Within FG I know it's possible to convert a string to a list (parseWords) but I just want to pull out certain items. Since LUA is built with tables as its only structure, it wasn't hard to implement a double-ended queue. Unfortunately building a data type and using it within the confines of FG are two different things ;). Given this code for the Double ended deque, how would I best utilize it in an extension environment for parsing or pattern matching.
List = {} -- global scope
function listNew ()
return {first = 0, last = -1};
end
function List.pushLeft (list, value)
local first = list.first - 1
List.first = first;
list[first] = value;
end
function pushRight (list, value)
local last = List.last + 1
List.last = last;
list[last] = value;
end
function popLeft (list)
local first = list.first;
if first > list.last then error("list is empty") end
local value = list[first];
list[first] = nil; -- to allow garbage collection
List.first = first + 1;
return value;
end
function popRight (list)
local last = list.last;
if list.first > last then error("list is empty") end
local value = list[last];
list[last] = nil; -- to allow garbage collection
List.last = last - 1;
return value;
end
List = {} -- global scope
function listNew ()
return {first = 0, last = -1};
end
function List.pushLeft (list, value)
local first = list.first - 1
List.first = first;
list[first] = value;
end
function pushRight (list, value)
local last = List.last + 1
List.last = last;
list[last] = value;
end
function popLeft (list)
local first = list.first;
if first > list.last then error("list is empty") end
local value = list[first];
list[first] = nil; -- to allow garbage collection
List.first = first + 1;
return value;
end
function popRight (list)
local last = list.last;
if list.first > last then error("list is empty") end
local value = list[last];
list[last] = nil; -- to allow garbage collection
List.last = last - 1;
return value;
end