lua-users home
lua-l archive

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


[snip]

> function base(x)
>   return {
>     ["meth1"] = function () return x end;
>     ["meth2"] = function () return 2 end
>   }
> end
> 
> function derived (x)
>   methods = base(x)
>   function meth1 () return 3 end
>   methods.meth1 = meth1
>   return methods
> end
> 
> d = derived(x)
> d.meth1() -- calls overriden meth1
> d.meth2() -- calls base meth2

[snip]

> function metaDerived (base)
>   methods = base()
>   ...

[snip]

> function anotherDerived (basetab)
>   function meth1 = ..
>   basetab.meth1 = meth1
>   return basetab
> end

[snip]

> So really, you just don't need OO when you have FP.

Not easy to read is it? I can't require that users of my applications
extend it using code like the above, they aren't experienced
programmers. Isn't the code bellow much easier to understand?

class TextButton extends Button -- or TextButton = class(Button) ... end
	local text

	constructor init(aText)
		text = aText
	end

	function draw(g)
		inherited draw(g)
		...
	end
end

b = new Button.init('Click me!') -- or some similar syntax

Regards,

André de Leiradella