DICE PACKS BUNDLE
  1. #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;
    end
    Aliens.... Go fig?

  2. #2
    Oh, and the function List,pushLeft was renamed pushLeft.
    Aliens.... Go fig?

  3. #3
    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

  4. #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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in