lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wednesday, February 19, 2014 08:53:05 AM Joachim Bürmann wrote:
> I'm trying to compare the binary chunk of two functions for equality.
> 
> The background:
> 
> I have to know if the body of a given function was changed. If so, the
> function must new applied to the recorded data.
> The difficulty:  Changed comments or the insertion of some syntax
> irrelevant white spaces must ignored!
> Otherwise every additional line feed or corrected comment forces a new
> call and redisplay of the protocol data (which sometimes is a time
> consuming process).

You should be able to do this with an AST compiled by metalua. Which should be 
easier to use now that it's been split into a metalua-parser rock. Here's a 
back-of-the-envelope example.


    function ast_compare(ast1, ast2)
        if ast1.tag ~= ast2.tag then
            return false
        end
        if #ast1 ~= #ast2 then
            return false
        end
        for i = 1, #ast1 do
            if type(ast1[i]) ~= type(ast2[i]) then
                return false
            end
            if type(ast1[i]) == 'table' then
                if not ast_compare(ast1[i], ast2[i]) then
                    return false
                end
            else
                if ast1[i] ~= ast2[i] then
                    return false
                end
            end
        end
        return true
    end

Completely untested, but that's the idea. Metalua stores debugging information 
in a 'lineinfo' field that can be ignored.

-- 
tom <telliamed@whoopdedo.org>