From 4e968529dca4ee98e801a2c89e4bbd229c96d6eb Mon Sep 17 00:00:00 2001 From: CPunch Date: Sun, 3 Jan 2021 17:35:52 -0600 Subject: [PATCH] __tostring example added --- examples/{newtest.cosmo => tostring.cosmo} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename examples/{newtest.cosmo => tostring.cosmo} (77%) diff --git a/examples/newtest.cosmo b/examples/tostring.cosmo similarity index 77% rename from examples/newtest.cosmo rename to examples/tostring.cosmo index 76eb3dc..3a807e2 100644 --- a/examples/newtest.cosmo +++ b/examples/tostring.cosmo @@ -3,14 +3,14 @@ proto test self.setArg(x) end - function fact(self) + function __tostring(self) var total = 1 for (var i = self.x; i > 0; i = i - 1) do total = total * i; end - return total + return "The factorial of " .. self.x .. " is " .. total end function setArg(self, x) @@ -24,6 +24,6 @@ for (var x = 1; x < 1000; x = x + 1) do for (var i = 1; i < 100; i = i + 1) do t.setArg(i) - print(t.fact()) + print(t) end end \ No newline at end of file