lua-users home
lua-l archive

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


> the problem that i am facing is that in my program i am intializing and 
creating
> an explosion effect from scripts ...... now each explosion can or cannot 
have a
> PS associated with it ..... this is determined by the value of a string 
...
> if there is a PS attached to the explosion the string contains the name 
and
> apth of the file that initializes the PS and if not then it contains 
"NULL"
> (not an empty string but the string "NULL")

I think you would be better off compiling the scripts and storing them
as compiled functions in a Lua table, perhaps with the explosion as
a key. Then you could use real Lua nils to indicate the absence of
a script.

> anyways now wat happens that during other calls to LUA the value of some
> of the string in the list of explosions gets overwritten by garbage
> ...... i have traced it down to the call :

> 0043C80F   call        _luaC_collectgarbage (0043cfd0)

> ..... this is the call that actually overwrites the memory location
> that is allocated to a C++ variable ......

Without actually seeing your code, I can't say for sure what is going
on but it sounds to me like you are storing the address of a Lua string
in a C++ pointer (const char* str = lua_tostring(L, -1);, for example),
and failing to make sure that the string doesn't get garbage collected.

Lua strings will get garbage collected without warning unless you
maintain a Lua reference to them, for example by keeping them on
the stack or by putting them into a table.

HTH.

Rici