Why does this not work...
TYPE Tmytype
foo$
ENDTYPE
GLOBAL testvar AS Tmytype
WHILE 1
myfunc(testvar)
WEND
FUNCTION myfunc: BYREF a AS Tmytype
a.foo$ = "Foo!"
ENDFUNCTION
... probably me doing something silly? I want to pass a custom type 'byref'...?
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2007.095 - 3D, NET
"test.gbas"(14) error : wrong argument type : myfunc, arg no: 1
Remove the BYREF. Types are passed by reference always...
That's bad, is it? It should be passed by value unless you explicitly want it, right?
Humm... Well, for now, it's just by reference.
Yep, all types should be treated the same (cept. array names and pointers).
Well at least I can go forward, Ill change it in the future if needed :)
I want to pass this array type byref, so i can store arrays with different array names.
How do you byref a type, which is declared as an array?
TYPE BezArray
x
y
ENDTYPE
GLOBAL Line1[] AS BezArray
DIM Line1[NumPoints]
QuadraticBezier3dLine( #,#,#,#,#,# , Line1[] as BezArray )
FUNCTION QuadraticBezierType: P0x , P0y , P1x , P1y , P2x , P2y, NumPoints , BYREF Array[] AS BezierArray
//Do stuff to the entire array type, and byref it back out to the proper array, array type.
RETURN Array[]
ENDFUNCTION
You cant return arrays as such - as they are passed BYREF anyway, you could always store back in there.
However, you can cheat if you want to pass an array back :
TYPE BezArray
x
y
ENDTYPE
TYPE BezArray2
lines[] AS BezArray
ENDTYPE
NumPoints=6
GLOBAL Line1[] AS BezArray
GLOBAL Line2 AS BezArray2
DIM Line1[NumPoints]
Line2=QuadraticBezier3dLine( 1,2,3,4,5,6,NumPoints, Line1[])
DEBUG Line1[0].x+"\n"
DEBUG Line2.lines[0].x+"\n"
END
FUNCTION QuadraticBezier3dLine AS BezArray2: P0x , P0y , P1x , P1y , P2x , P2y, NumPoints , Array[] AS BezArray
LOCAL temp AS BezArray2
//Do stuff to the entire array type, and byref it back out to the proper array, array type.
//RETURN Array[]
Array[0].x=123
DIM temp.lines[6]
temp.lines[0].x=999
RETURN temp
ENDFUNCTION
Thanks buddy :coke: