lua-users home
lua-l archive

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


Hi there,

I am using Lua a lot in my game with great success. I exposed my game  
API via toLua to my scripts. But now I have a "typical" C/pointer  
problem:

In my script I do something like that:

my_enemy = enemy_class:create_enemy()

This returns a userdata (?) pointing to the enemy object which was  
created by the C++ function create_enemy.

Now this enemy is destroyed and deleted inside the C++ code and  
"my_enemy" is pointing to neverland (and causing a crash when accessed).

So, is there an "elegant" way to set such rogue userdata objects to nil?

Actually I work around this problem with calling a "enemy_dead()" LUA  
function from C code when an enemy object is about to be destroyed. In  
this function I'm looping through my globals and set the ones pointing  
to the enemy to nil.

It'd be perfect If I could reset these variables directly from my C++  
code so that all Lua userdata objects will point to nil when the enemy  
is destroyed.

Thanks for your help.
Jens