lua-users home
lua-l archive

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

With regard to injection, it's interesting to look at Michael Franz's paper on Protocol Extension.

Essentially, he uses the module system in Oberon to avoid name conflicts on extensions.

In the context of something like the method chaining wrapper, one could write:

	local stringx = require "stringx"

	S "  test  " : [ stringx.trim ] () ()

(This assumes a Lua extension to support calling methods identified by variables. The patch to support this looks reasonably simple, but I haven't pushed hard on it.)

Or for more efficient execution, one could write:

	local stringx = require "stringx"
	local stringx_trim = stringx.trim

	S "  test " : [ stringx_trim ] () ()

Of course, this then raises the question, why not just name the method "stringx_trim" and be done with it:

	S "  test " : stringx_trim() ()

One answer might be that the method chaining wrapper could handle functions passed as indices by returning the function itself. Then stringx.trim isn't just an identifier for the method, it can actually be the method implementation.