Skip to content

Commit d13e739

Browse files
Use the Nameable and Stringifiable mixins in the Oscillogram class
1 parent dd39911 commit d13e739

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

oscillogram.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- luacheck: no max comment line length
2+
13
---
24
-- @classmod Oscillogram
35

@@ -52,6 +54,24 @@ end
5254
-- @treturn Oscillogram self
5355
-- @treturn number always zero
5456

57+
---
58+
-- @treturn tab table with instance fields
59+
-- (see the [luaserialization](https://github.com/thewizardplusplus/luaserialization) library)
60+
function Oscillogram:__data()
61+
return {
62+
kind = self._kind,
63+
points = self._points,
64+
default = self._default,
65+
minimum = self._minimum,
66+
maximum = self._maximum,
67+
}
68+
end
69+
70+
---
71+
-- @function __tostring
72+
-- @treturn string stringified table with instance fields
73+
-- (see the [luaserialization](https://github.com/thewizardplusplus/luaserialization) library)
74+
5575
---
5676
-- @function push
5777
-- @tparam number point

oscillogram_test.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ function TestOscillogram.test_new_partial()
4949
luaunit.assert_equals(plot._maximum, 1)
5050
end
5151

52+
function TestOscillogram.test_tostring()
53+
local plot = Oscillogram:new("random", 5, 32, 23, 42)
54+
local text = tostring(plot)
55+
56+
luaunit.assert_is_string(text)
57+
luaunit.assert_equals(text, "{" ..
58+
"__name = \"Oscillogram\"," ..
59+
"default = 32," ..
60+
"kind = \"random\"," ..
61+
"maximum = 42," ..
62+
"minimum = 23," ..
63+
"points = { 32, 32, 32, 32, 32 }" ..
64+
"}")
65+
end
66+
5267
function TestOscillogram.test_update_custom()
5368
local plot = Oscillogram:new("custom", 0, 0.5)
5469
for i = 1, 5 do

0 commit comments

Comments
 (0)