lua-users home
lua-l archive

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


So hang on, would this mean that, as a host app or module writer, I can no longer rely on this to work:
 
  t = { 1,2,3 }
  print(t[2])
  -> 2
 
if some other module or user script has gone and installed a ‘clever’ type metatable?
 
I realise this is currently the case with string, but there’s a lot less incentive to do clever things with that.
 
Like I said, I like the concept, but I wonder if there is some way this could be made _ENV bound, or similar, to avoid nasty side-effects in other modules.
 
- Claire.
 
 
From: John Hind
Sent: Wednesday, December 05, 2012 10:16 PM
Subject: Type Metatables for Table and Userdata - Powerpatch
 

Please take a look at my new PowerPatch at http://lua-users.org/wiki/LuaPowerPatches. This allows the Table and Userdata types to have type metatables without losing their current per-object ones. This new mechanism is then used to expose the Table Library as methods of Table objects in the same way the String Library is exposed for String objects. (Logically, 'pairs', 'ipairs' and 'next' should also be exposed as methods, but I have not done that in the patch.) For very little cost, this makes Lua more consistent and also adds a powerful new generalised mechanism for others to build on.

 

While there, you could maybe take another look at my 'Self-iterating Objects' patch further down the same page. Having used this extensively myself over the last few years, I am more than ever convinced this is a worthwhile improvement.

 

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2221 / Virus Database: 2629/5437 - Release Date: 12/04/12