lua-users home
lua-l archive

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


Sam Roberts wrote:
[...]
> Its not clear to me what the function of this is, why this is useful.

It's because there are an awful lot of operations that you might want to apply
to strings --- string.find(), string.match(), string.gsub(), etc. By
special-casing string's metatable like that, it means you can call the
functions in the string library on a string as if it were a method. i.e.,
s:find(), s:match(), s:gsub() etc. This makes life considerably easier.

It hasn't, AFAIK, been considered worth it to do this for the other builtin
types, but I suppose it could be useful for some (such as number).

Note that for obvious reasons you can't do this for tables!

-- 
+- David Given --McQ-+ "Gaping from its single obling socket was
|  dg@cowlark.com    | scintillating, many fauceted scarlet emerald..."
| (dg@tao-group.com) | --- Jim Theis, _The Eye of Argon_ (spelling
+- www.cowlark.com --+ original)


Attachment: signature.asc
Description: OpenPGP digital signature