On 8/10/19 12:00 PM, David Epstein via use-livecode wrote:
I want to write a function that will read and write to any named global. What
I have below seems to work, but I’m not sure quite why. Usually, “put gName
into oldVal” for a global named gName would put the value, not the name, of
that global into oldVal. But here it does not.
function globalSwap gName,gVal
-- Return the existing value of global gName and load gVal into that same
global
do "global" && gName
do "put" && gName && "into oldVal" # "put gName into oldVal" doesn't work
here.
do "put gVal into" && gName
return oldVal
end globalSwap
Is there some way to write this with fewer or no uses of “do”?
Well, the best way, of course, is not to use globals.
Barring that (watch the wordwrap),
function globalSwap gname, pVal
local tOldVal, tCommand
put "global"&&gName&&";put"&&gName&&"into
tOldVal;put"&&pVal&&"into"&&gName into tCommand
do tCommand
return tOldVal
end globalSwap
--
Mark Wieder
ahsoftw...@gmail.com
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode