lua-users home
lua-l archive

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

Jose Marin wrote:
> I see two main ways of implementing Lua event handlers in a game:
> ..snip..

Quoting the reference manual:

3.5 - Registry
Lua provides a registry, a pre-defined table that can be used by any C code to
store whatever Lua value it needs to store. This table is always located at
pseudo-index LUA_REGISTRYINDEX. Any C library can store data into this table,
but it should take care to choose keys different from those used by other
libraries, to avoid collisions. Typically, you should use as key a string
containing your library name or a light userdata with the address of a C object
in your code.

The integer keys in the registry are used by the reference mechanism,
implemented by the auxiliary library, and therefore should not be used for other

So you can’t use integer indexes in to the registry because auxlib owns those.
But you could use this *concept* in your own implementation. So use your own
table, indexed with integer keys. Now you just need somewhere to store that
table. Maybe as an upvalue? I’m actually not sure, but this reduces the problem
from storing 100+ event handler function references to storing one table
reference. Is that useful?

Good luck,

 - Peter Odding