[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_State: Overhead and code retention
- From: Arvid Norberg <c99ang@...>
- Date: Sat, 11 Jan 2003 03:28:15 +0100
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