lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Joachim Bürmann
> Sent: woensdag 19 februari 2014 10:14
> To: Ico Doornekamp
> Cc: lua-l
> Subject: Re: Comparing the binary chunk of two functions for equality
> 
> Hello Ico,
> 
> thank you very much for your fast response.
> 
> > * On 2014-02-19 08:53:05 +0100, Joachim Bürmann wrote:
> >
> > > 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).
> > >
> > > Unfortunatelly it seems that different white spaces or different
> > > comments lead to a different chunk (or byte code).  My hope was that
> > > comparing only the chunk gets me rid of removing all comments and
> > > spare white spaces by hand.
> >
> > My guess is that the debug info in the lua chunk changes with the
> > layout of your source, there is at least information stored about line
> > numbers of functions etc.
> 
> Yes, indeed that would explain it. I never thought about that.
> 
> >
> >
> > > I would really appreciate it someone is able to put some light on
> > > this matter.
> >
> > I'm not sure of comparing binary chunks is the way to go, you are
> > depending too much on the implementation to tell you if the source has
> > changed.
> >
> > You might have more luck with processing the sources by removing all
> > (non-string) whitespace of both versions and comparing the resulting
> > strings.
> >
> 
> I was afraid that I have to do this and I already started with it.
> Luckily it's not as complicated as it appears at a first glance...
> 
> Ok, thanks for your response and best regards
> 
> Joachim
> 

There are some 'minifiers' that can pack scripts together (Squish [1] for example). I suggest using one of those. Just make sure to use one that doesn't retain source lines/debug info nor uses any obfuscation, but maximizes on size reduction. I think that’s your best bet to get equal bytecode chunks.

Thijs

[1] http://matthewwild.co.uk/projects/squish/readme.html