Hi!
Does anybody know how I can pass an objref array by reference to a function?
I want to do something like:
// begin
func foo(){localobj arr
arr = $o1
arr[0]=new Vector(10)
arr[1]=new Vector(20)
return ERR_OK
}
objref arr[2]
foo(arr)
// end
Thanks
Passing an objref array by reference to a function
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
I've always found arrays to be limiting, because no matter how many objects
I think I need today, sure enough, tomorrow I need a different number. Lists
are a far more flexible way to deal with multiple objects, even objects of
different classes (although this simple example sticks with objects of the
same kind).
I think I need today, sure enough, tomorrow I need a different number. Lists
are a far more flexible way to deal with multiple objects, even objects of
different classes (although this simple example sticks with objects of the
same kind).
Code: Select all
objref bah
bah // will print NULLobject
proc foo() { local ii
$o1 = new List()
for ii=0,$2-1 $o1.append(new Vector())
}
foo(bah,3)
bah // will print List...
bah.count() // shows it contains objects
for jj=0,bah.count()-1 print bah.object(jj) // says what they are
There is no direct way to pass an objref array to a function. Probably the least violent transformation to existing code is to make use of a wrapper object as is done with strdef.
The every occurrence of an array variable becomes variable.o and instead of declaring
one declares
where
The every occurrence of an array variable becomes variable.o and instead of declaring
Code: Select all
objref variable[n]
Code: Select all
objref variable
variable = new ObjectArray(n)
Code: Select all
begintemplate ObjectArray
public o, n
objref o
proc init() {
n=$1
objref o[n]
}
endtemplate ObjectArray