lua-users home
lua-l archive

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


On 5 June 2014 01:45, Andrew Starks <andrew.starks@trms.com> wrote:
>
> On Wed, Jun 4, 2014 at 11:31 PM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>>
>> > I THINK (and I'm not certain) that differing line numbers in the debug
>> > info is enough to mark them as "different". I think "similar enough"
>> > essentially refers to two functions being instantiated by different
>> > iterations of the same line of code.
>>
>> Right.
>
>
> Okay. This is (pretty much) the whole constructor:
>
> local function url(url_str)
> local self
> if type(url_str) == "string" then
> self = url_pat:match(url_str)
> elseif type(url_str) == "table" and url_str.url then
> return url(url_str.url)
> end
>
>
> if self then
> self.socket = self.host ..
> (self.port and (":"..("%d"):format(self.port)) or "")
> self[0] = self.socket
> self.xpath = xpath:match(url_str)
> self.url = self.protocol .. "://" .. self.xpath
> self.route = route
> return setmetatable({}, {
> --for brevity, I'm only including the function in question.
> __eq = function(a, b) return a.url == b.url end ,
>
> })
> end
>
> end
>
> This would seem to support "similar enough".
>
> If I run tests in the same file as this code, it never fails to see the
> functions as the same.
>
> --...
> --complete module definition is above this comment...
>
> for i = 1, 10001 do
> local a = url("mcp://host/thread/name/"..tostring(i))
> collectgarbage()
> local b =  url("mcp://host/thread/name/"..tostring(i) .."/")
> assert(a == b)
> end
> print("passed!")
> -->  passed!
>
> If I run them in a different file (require the module), it _often_ does.
> That is, it's not only within Lua Busted.
>
> If I run the garbage collector between assignments, it will fail every time.
>
> local url = require'mediacircus.url'
>
> local a = url("mcp://host/thread/name")
> collectgarbage()
> local b = url("mcp://host/thread/name/")
> print(a == b)
> --> false
> print(getmetatable(a).__eq, getmetatable(b).__eq)
> --> function: 00000000004337D0 function: 00000000003E9550
>
>
> Is this expected? Can you provide some insight as to how I can understand
> this better?

By any chance, are your command-line invocations and the `busted`
script launching different Lua interpreters?

-- Hisham