Wiki

Clone wiki

glLoadGen / MD_Test

This is a markdown test page.

I'm markdown. JOY!

Section 1

<a name="Section 1">

Subsection Alpha

require "ufs"

local function GetPathIterator(path)
    local theItData = {path:iterator()}
    local theItFunc = theItData[1];
    table.remove(theItData, 1);

    return theItFunc, theItData;
end

function make_relative(mainPath, absPath)
    if(mainPath:root_path():empty() or not mainPath:is_absolute()) then
        return mainPath;
    end

    if(mainPath:root_path():empty() or not absPath:is_absolute()) then
        return mainPath;
    end

    if(absPath:root_name() ~= mainPath:root_name()) then
        return mainPath;
    end

    local currdirPath = ufs.path(".");

    if(absPath:filename() ~= currdirPath) then
        absPath = absPath / currdirPath;
    end

    local mainItFunc, mainItData = GetPathIterator(mainPath);
    local baseItFunc, baseItData = GetPathIterator(absPath);

    while(true) do
        mainItData[2] = mainItFunc(unpack(mainItData));
        baseItData[2] = baseItFunc(unpack(baseItData));

        if(mainItData[2] ~= baseItData[2]) then
            break;
        end

        if(baseItData[2] == nil or mainItData[2] == nil) then
            break;
        end
    end

    --for each element of baseItData left, add a ".." to the path.
    local numBack = 0;

    while(baseItData[2] and baseItData[2] ~= currdirPath) do
        print(baseItData[2]);
        numBack = numBack + 1;
        baseItData[2] = baseItFunc(unpack(baseItData));
    end

    if(not baseItData[2] or baseItData[2] == currdirPath) then
        --Take the current path and everything below it
        local newPath = ufs.path();

        for i=1, numBack do
            newPath = newPath / ufs.path("..");
        end

        while(mainItData[2]) do
            newPath = newPath / mainItData[2];
            mainItData[2] = mainItFunc(unpack(mainItData));
        end

        return newPath;
    end

    return mainPath;
end

Possible section link: Section 1

Updated