NG - Operator overloading?

Started by markcwm, July 22, 2017, 23:11:19

Previous topic - Next topic

markcwm

Hi,

DruggedBunny added a few operator overloads to Openb3d but they won't compile. The message is:
Compile Error: Syntax error - expecting '('.
So does anyone know how this works in NG? Here's a testing sample:
Code (blitzmax) Select
' operators.bmx

Local m1:TMesh=New TMesh
Local m2:TMesh=New TMesh
End

Type TMesh

' Operator overloading in bmx-ng allows adding/subtracting meshes,
' eg. "mesh3 = mesh1 + mesh2" to produce new mesh with CSG operations

Const CSG_SUBTRACT:Int = 0 ' Method 0 subtracts mesh2 from mesh1
Const CSG_ADD:Int = 1 ' Method 1 adds meshes
Const CSG_INTERSECT:Int = 2 ' Method 2 intersects meshes

Function MeshCSG:TMesh( m1:TMesh,m2:TMesh,method_no:Int=1 )

End Function
?bmxng
Method Operator+:TMesh(add_mesh:TMesh)
Return MeshCSG(Self, add_mesh, CSG_ADD)
End Method

Method Operator-:TMesh(add_mesh:TMesh)
Return MeshCSG(Self, add_mesh, CSG_SUBTRACT)
End Method
?
End Type

GW

Are you using the latest version of NG?

markcwm

Ah, no on Windows I'm using NG 0.77, that must be it. Cheers GW.

markcwm

#3
Yeah, operator overloads were added about Nov 2016 to bcc, which means any release older than v0.87 doesn't support them. I got it working using the latest NG.

Btw, to use them the syntax is:
Code (blitzmax) Select
Local tube:TMesh=CreateCylinder(32)
Local tube2:TMesh=CreateCylinder(32)

Local csg:TMesh=tube+tube2
'Local csg2:TMesh=MeshCSG(tube,tube2,1) ' 1=add