lua-users home
lua-l archive

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


> > The metatable of `string` is itself.  It has a method __index.
> > So it seems to be a feature, not a bug. :-)
> 
> Yes. But I cannot see what can be that feature.
> >From the sources, the __index field inside `string` is a function
> whose only purpose is to throw an error.
> Why is that function needed?? In all other module tables (like table,
> os, io, ...) indexing the table with an non-existent field simply
> returns nil.

It is used to detect errors like this:

  print(s:fomat("%.4d"))

You should use 'rawget' in your tests for an __index field. (That is
how Lua accesses those fields, after all.)

-- Roberto