08-16-2023, 12:33 PM
It hit me like a thunderbolt.
What sucks is it has to be a SUB and depend on the parameter side-effect. Because FUNCTION declaration has to carry a sigil, it's impossible to have it return the contents of an UDT variable, or even of _MEM. Somehow this should be doable as AddVector%&().
But I think Terry means a general conversion of any UDT into a function or something like that.
Code: (Select All)
TYPE TYPE_VECTOR
x AS SINGLE
y AS SINGLE
END TYPE
DIM AS TYPE_VECTOR v1, v2, v3
v1.x = 10: v1.y = 20
v2.x = 15: v2.y = 15
AddVector v1, v2, v3
PRINT "Result x ="; v3.x
PRINT "Result y ="; v3.y
'CHANGED: tret
SUB AddVector(v1 AS TYPE_VECTOR, v2 AS TYPE_VECTOR, tret AS TYPE_VECTOR)
DIM AS _MEM m1, m2
DIM AS SINGLE a, b
DIM AS INTEGER l
m1 = _MEM(v1)
m2 = _MEM(v2)
a = _MEMGET(m1, m1.OFFSET, SINGLE)
b = _MEMGET(m2, m2.OFFSET, SINGLE)
a = a + b
tret.x = a
l = LEN(a)
a = _MEMGET(m1, m1.OFFSET + l, SINGLE)
b = _MEMGET(m2, m2.OFFSET + l, SINGLE)
a = a + b
tret.y = a
'AddVector.x = v1.x + v2.x
'AddVector.y = v1.y + v2.y
END SUB
What sucks is it has to be a SUB and depend on the parameter side-effect. Because FUNCTION declaration has to carry a sigil, it's impossible to have it return the contents of an UDT variable, or even of _MEM. Somehow this should be doable as AddVector%&().
But I think Terry means a general conversion of any UDT into a function or something like that.