lua-users home
lua-l archive

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

> On Sun, Jun 8, 2014 at 4:06 AM, Michal Kottman <>
> wrote:

> Anyway, I imagine in C++ "dependency injection" would have more
> limitations -- you'd have to go to greater lengths to support moving
> in dependencies of polymorphic types.  In a language like Javascript
> or Lua (duck-typing languages) it's a bit easier.

Yes. Very basic dependency injection in Lua is easy and can be
very useful.

For instance, most code using Redis in a model would probably
take the address of the Redis server as a parameter and require
its Redis client library internally. But if you write code that
takes an initialized instance of a client, you can easily support
redis-lua (in normal code), resty-redis (in OpenResty) and
fakeredis (for tests).

Of course the downside of dynamism is that nothing checks that
what you pass in supports the interface you expect (at least not

Pierre Chapuis