PDA

View Full Version : Parsing in FG LUA



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

S Ferguson
January 20th, 2013, 04:43
Oh, and the function List,pushLeft was renamed pushLeft.

Moon Wizard
January 26th, 2013, 22:18
You can define the queue functions in a separate "package" in the extension. Take a look at how "StringManager" is defined and used in the 3.5E ruleset.

Regards,
JPG

S Ferguson
January 26th, 2013, 22:24
Thanks. And I hope the library helped.