lua-users home
lua-l archive

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


At 2003-01-10 15:52, you wrote:
Could you elaborate on this idea? I am not sure what you mean...

I was thinking of lua_setglobals(), it's undocumented and it didn't work exactly as I first expected. It lets you select a table that is to be used for global variables inside a function. You could put your entities' functions in a table per entity instance and then set each function's globals-table to itself, like this:


player = {}
monster = {}

player.f = function(x) a = x end
player.g = function() return a end

monster.f = function(x) a = x end
monster.g = function() return a end

setglobals(player.f, player)
setglobals(player.g, player)

setglobals(monster.f, monster)
setglobals(monster.g, monster)


player.f(0)
monster.f(1)

print(player.g()) -- will print 0
print(monster.g()) -- will print 1

Hope it is to any help.

---
Arvid Norberg