|
Petite Abeille wrote:
local Data = require( 'Data' ) -- save the content of table 't' to file 't.txt' Data[ 't.txt' ] = t -- load the content of file 't.txt' into variable 't' t = Data[ 't.txt' ]
Wow, that's one crazy looking interface! Why bother with encode(t/s), write(file, t) or read(file) when you can use __call, __index and __newindex!
It reminds me of the gyrations I went through when I discovered all the amusing ways to use C++ operator overloading. Lots of fun! Heck, in C++ some of it became part of std::.
Other than the obvious fun, though, is there a benefit I've missed to having the implementation use __call, __index, and __newindex? The indexing doesn't make me think "writing/reading a file". Why not just use two named functions for the API? Brevity? Couldn't that also be achieved with local tread = data.read?
Just curious. Doug