lua-users home
lua-l archive

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


Hi,

>  I'm new to Lua (since yesterday)

Welcome!

> I think this could be a performance problem when
> using a lot of variable of the same type as X. Is there a way to make
> this  work with only one large table ?

Yes.  But let me say that Lua has no problems with *huge* tables, so don't
worry...

What you need is the metatable concept, especially its __index member.  Have
a look at section 2.8 of the manual (assuming you're using Lua 5)

http://www.lua.org/manual/5.0/manual.html#2.8

The metatable essentially plays the role you indicated with your "X.type"
construction and then some.  There are many examples of how to use
metatables.  Browse through the lua archive and the wiki at
www.lua-users.org

--
Wim