Skip to content

Commit e0a47d5

Browse files
authored
Merge pull request #102 from moteus/master
Add. `__tostring` methods to classes.
2 parents 9ac72c7 + 479636f commit e0a47d5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lua/cURL/impl/cURL.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ local module_info = {
1515
_COPYRIGHT = "Copyright (c) 2014-2017 Alexey Melnichuk";
1616
}
1717

18+
local function hash_id(str)
19+
local id = string.match(str, "%((.-)%)") or string.match(str, ': (%x+)$')
20+
return id
21+
end
22+
1823
local function clone(t, o)
1924
o = o or {}
2025
for k,v in pairs(t) do o[k]=v end
@@ -485,6 +490,11 @@ function Form:add(data)
485490
return form_add(self, data)
486491
end
487492

493+
function Form:__tostring()
494+
local id = hash_id(tostring(self._handle))
495+
return string.format("%s %s (%s)", module_info._NAME, 'Form', id)
496+
end
497+
488498
end
489499
-------------------------------------------
490500

@@ -570,6 +580,11 @@ function Easy:setopt(k, v)
570580
return setopt(self, k, v)
571581
end
572582

583+
function Easy:__tostring()
584+
local id = hash_id(tostring(self._handle))
585+
return string.format("%s %s (%s)", module_info._NAME, 'Easy', id)
586+
end
587+
573588
end
574589
-------------------------------------------
575590

@@ -687,6 +702,11 @@ function Multi:setopt(k, v)
687702
return setopt(self, k, v)
688703
end
689704

705+
function Multi:__tostring()
706+
local id = hash_id(tostring(self._handle))
707+
return string.format("%s %s (%s)", module_info._NAME, 'Multi', id)
708+
end
709+
690710
end
691711
-------------------------------------------
692712

0 commit comments

Comments
 (0)