lua-users home
lua-l archive

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


> When SetTitle() is called the 3rd time to restore the title, it sets the
> title to "String 2", not to sOldTitle, which is what I had intended.
> I think I see what is happening (is this correct?):  I have assigned
> sOldTitle as the value of SetTitle(), so the fact that I did not update
> sOldTitle by the second call to SetTitle() means that sOldTitle was
> automatically updated by lua_pushstring() inside SetTitle().

This is not what is happening.

Unless you explicitly set the value of the sOldTitle global from within
your SetTitle function, or does some other magic that has that effect,
there is no way sOldTitle will be changed by the second call.

Weird things can happen if you modify the strings in C.  You are not
supposed to modify the strings that Lua returns to you. If you do so, it
could well cause the value pointed to by sOldTitle to change...

Can you run this instead?

    sOldTitle = SetTitle( "String 1" )
    SetTitle( "String 2" )
    SetTitle( sOldTitle )

If sOldTitle changes between the first and second print, send us your C
code for SetTitle and we will figure out what is going on.