Ooops
October 16, 2021, 00:26:41

Author Topic: NG - Operator overloading?  (Read 2279 times)

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
NG - Operator overloading?
« on: July 22, 2017, 23:11:19 »
Hi,

DruggedBunny added a few operator overloads to Openb3d but they won't compile. The message is:
Code: [Select]
Compile Error: Syntax error - expecting '('.So does anyone know how this works in NG? Here's a testing sample:
Code: BlitzMax
  1. ' operators.bmx
  2.  
  3. Local m1:TMesh=New TMesh
  4. Local m2:TMesh=New TMesh
  5. End
  6.  
  7. Type TMesh
  8.  
  9.         ' Operator overloading in bmx-ng allows adding/subtracting meshes,
  10.         ' eg. "mesh3 = mesh1 + mesh2" to produce new mesh with CSG operations
  11.        
  12.         Const CSG_SUBTRACT:Int  = 0 ' Method 0 subtracts mesh2 from mesh1
  13.         Const CSG_ADD:Int               = 1 ' Method 1 adds meshes
  14.         Const CSG_INTERSECT:Int = 2 ' Method 2 intersects meshes
  15.        
  16.         Function MeshCSG:TMesh( m1:TMesh,m2:TMesh,method_no:Int=1 )
  17.        
  18.         End Function
  19. ?bmxng
  20.         Method Operator+:TMesh(add_mesh:TMesh)
  21.                 Return MeshCSG(Self, add_mesh, CSG_ADD)
  22.         End Method
  23.        
  24.         Method Operator-:TMesh(add_mesh:TMesh)
  25.                 Return MeshCSG(Self, add_mesh, CSG_SUBTRACT)
  26.         End Method
  27. ?
  28. End Type
  29.  

Offline GW

  • Full Member
  • ***
  • Posts: 222
Re: NG - Operator overloading?
« Reply #1 on: July 23, 2017, 00:19:01 »
Are you using the latest version of NG?

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: NG - Operator overloading?
« Reply #2 on: July 23, 2017, 01:52:46 »
Ah, no on Windows I'm using NG 0.77, that must be it. Cheers GW.

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: NG - Operator overloading?
« Reply #3 on: July 23, 2017, 21:17:15 »
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
  1. Local tube:TMesh=CreateCylinder(32)
  2. Local tube2:TMesh=CreateCylinder(32)
  3.  
  4. Local csg:TMesh=tube+tube2
  5. 'Local csg2:TMesh=MeshCSG(tube,tube2,1) ' 1=add
« Last Edit: July 23, 2017, 21:19:38 by markcwm »

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal