[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Q on functions as first class values
- From: "Michael Newberry" <mnewberry@...>
- Date: Wed, 2 Feb 2005 12:14:56 -0700
I think I have a found a limitation to the "functions as first class values"
design. Can someone please verify the following?
Here is code that calls a C function SetTitle() three times. SetTitle() sets
a new string value in C-code and returns the previous one:
sOldTitle = SetTitle( "String 1" )
SetTitle( "String 2" )
SetTitle( sOldTitle )
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(). Is this
correct? If so, then I could solve the problem by using a dummy value to
catch the unused return from the second call to SetTitle(). But I wonder if
there is a better way; otherwise that is a "gotcha" waiting to happen again.
Thanks,
Michael Newberry