Thread: Parsing in FG LUA
-
January 20th, 2013, 04:36 #1
Parsing in FG LUA
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;
endAliens.... Go fig?
-
January 20th, 2013, 04:43 #2
Oh, and the function List,pushLeft was renamed pushLeft.
Aliens.... Go fig?
-
January 26th, 2013, 22:18 #3
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
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
-
January 26th, 2013, 22:24 #4
Thanks. And I hope the library helped.
Aliens.... Go fig?
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks