[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Aspect Oriented Programming
- From: Javier Guerra Giraldez <javier@...>
- Date: Mon, 3 Jan 2011 16:52:34 -0500
2011/1/3 Gustavo de Sá Carvalho Honorato <gustavohonorato@gmail.com>:
> Hi,
>
> is there any easy way to work with Aspects in Lua? I've found this
> project (http://aspectlua.luaforge.net/) but it seems to be quite old.
as many things OO, most 'fun' things in aspects are trivial to do in
functional programming:
for example, it's common to enhance the built-on type() function:
do
local oldtype = type
function type(x)
local mt = getmetatable(x)
if mt and mt.__type then return mt.__type end
return oldtype(x)
end
end
or you could do some 'prepend' functions:
function prepend(f,pre)
return function(...)
return pre(f,...)
end
end
and use like this:
type = prepend (type, function(old, x)
local mt = getmetatable(x)
if mt and mt.__type then return mt.__type end
return old(x)
end
--
Javier