From ae2f864873a8af097b1b4ec5ff020ec2d8d33d85 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 4 Jan 2016 11:55:49 +0100 Subject: allow constructors to return other things than class instances * could be used to introduce classes like SinOsc that are simply shortcuts for some higher order stream (just like Stream.SinOsc is currently) but can be instantiated consistently using SinOsc:new(). --- applause.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applause.lua b/applause.lua index d598a86..1455dc5 100644 --- a/applause.lua +++ b/applause.lua @@ -98,9 +98,9 @@ function DeriveClass(base, ctor) setmetatable(obj, self) - if ctor then ctor(obj, ...) end - - return obj + -- Allow constructors to return something else + -- than an instance of the class. + return ctor and ctor(obj, ...) or obj end return class -- cgit v1.2.3