lua-users home
lua-l archive

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


Very interesting, I will try and report back.

Thank you VERY much!


"Arvid Norberg" <c99ang@cs.umu.se> wrote in message
5.2.0.9.0.20030110181757.02cc98b0@mail.cs.umu.se">news:5.2.0.9.0.20030110181757.02cc98b0@mail.cs.umu.se...
> 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
>
>