Can't pass array function result as parameter

David Burgun dburgun at dsl.pipex.com
Thu Mar 30 11:00:37 EST 2006


Hi.

Depending on how you have coded it, there will be 2 copies of the  
array, e.g.

if you do this in the library:

local sgLibArray

function LibGetArray
return sgLibArray
end LibGetArray


function LibChangeArray theArray,theKey,theData
put theData into theArray[theKey]
end LibChangeArray


on mouseUp
put LibGetArray() into myArray

get LibChangeArray(myArray)
end mouseUp


Then there will be one copy of the array stored in gLibArray (in the  
library stack) and one stored in myArray (in the client stack).  
LibChangeArray() will change the copy in myArray and then return, the  
mouseUp handler will return and myArray will be destroyed.

In order to fix this you'd have to add the following line to  
LibChangeArray:

put theArray into sgLibArray

AFAIK, this means the array is copied twice, there may be a way to  
save this copying by use of the "@" keyword but if so I haven't been  
able to figure out how to do it.

Hope this helps
All the Best
Dave

On 30 Mar 2006, at 05:42, James Spencer wrote:

> Can anyone confirm this problem.  I'm getting an array from a  
> function in a library.  I modify that array and then pass it to a  
> handler also in the library.  The debugger is showing that the  
> modified array is valid and contains what it should but the  
> parameter in the library is shown as empty.  I've found a work  
> around by copying the elements of the array to a new array and  
> passing that but obviously this should not be necessary.
>
> Bugzilla shows a bug in the Windows version of 2.7 that is probably  
> the same bug, #3411, but there, the poster stated that they could  
> resolve the problem by simply placing the array they are getting  
> from the function into a temporary variable and then passing that  
> where I'm seeing the problem even when I put it into a temp (as I'm  
> necessarily doing as I modify the array before passing back to the  
> library again.
>
> James P. Spencer
> Rochester, MN
>
> jspencer78 at mac.com
>
> "Badges??  We don't need no stinkin badges!"
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list