I don't think it can be done in that case. Well, there's an unsafe way of doing 
it if you know that the two types are binary compatible and of the same size.
    
    
    type
      Obj = object
        m: cint
    
    static:
      doAssert(sizeof(cint) == sizeof(int32))
    
    proc `m`*(o: var Obj): var int32 =
      cast[ptr int32](addr o.m)[]
    
    var obj: Obj
    obj.m += 5
    echo obj.m   # 5
    
    
    Run

buuut this is extremely situational and I wouldn't recommend it at all. You're 
best off just making shorthand procedures that act on the object itself.
    
    
    type
      Obj = object
        m: cint
    
    proc incM*(o: var Obj, n: int) =
      o.m = cint(int(o.m) + n)
    
    proc decM*(o: var Obj, n: int) =
      o.m = cint(int(o.m) - n)
    
    var obj: Obj
    obj.incM(5)
    echo obj.m   # 5
    
    
    Run

Reply via email to