Reading and writing globals by script

David Epstein dfepstein at comcast.net
Sat Aug 10 15:00:54 EDT 2019


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”?

David Epstein



More information about the use-livecode mailing list