Passing parameters by reference

Dick Kriesel dick.kriesel at
Sat Mar 10 03:06:45 EST 2012

On Mar 9, 2012, at 5:05 PM, Dar Scott wrote:

> Maybe the array could be global (or passed as a parameter) and the subscript passed. ... There might be problems I don't see right off, such as access to the same array at two different levels at the same time. 

Hi, Dar.  LC has a way to get and set a node at any level of an array, without code that concatenates [ ] to specify the node.  In an array reference a single [ ] can enclose an array of keys, as you can see in the code below.  Put the following into a button and click it.  The code invokes the debugger so you can see the array and the result string on the variables tab.

I agree it'd be good if LC could accept any array reference for invoking a handler that specifies pass-by-reference.  Pete, I'd be glad to vote for your enhancement request.

-- Dick

on mouseUp
   local tArray, tString
   put 4 into tArray[ 1 ][ 2 ][ 3 ]
   put getNodeViaListOfKeys( tArray, ( 1, 2, 3 )) after tString -- that is, get tArray[ 1 ][ 2 ][ 3 ]
   setNodeViaListOfKeys tArray, ( 5, 6, 7, 8 ), 9 -- that is, put 9 into tArray[ 5 ][ 6 ][ 7 ][ 8 ]
   put comma & getNodeViaListOfKeys( tArray, ( 5, 6, 7, 8 )) after tString -- 4,9
end mouseUp

function getNodeViaListOfKeys @pArray, pList
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   return getNodeViaArrayOfKeys( pArray, tKeys )
end getNodeViaListOfKeys

function getNodeViaArrayOfKeys @pArray, @pKeysArray
   return pArray[ pKeysArray ]
end getNodeViaArrayOfKeys

command setNodeViaListOfKeys @rArray, pList, pValue
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   setNodeViaArrayOfKeys rArray, tKeys, pValue
end setNodeViaListOfKeys

command setNodeViaArrayOfKeys @rArray, @pKeysArray, @pValue
   put pValue into rArray[ pKeysArray ]
end setNodeViaArrayOfKeys

More information about the Use-livecode mailing list