     public init(vm: HSQUIRRELVM) {
         self.vm = vm
         stack = Stack(vm: vm)
-        (stack as! Stack).parent = self
+        vm ~ self
     }
     
     convenience public init(stackSize: Int) {

                var obj: HSQOBJECT = HSQOBJECT()
                sq_resetobject(&obj)
                sq_getstackobj(vm, SQInteger(position), &obj)
                return .Object(SQTable(vm: parent!, object: obj))
                
            default:
                return .Null

        
        // MARK: - SquirrelVM::Stack::private
        private let vm: HSQUIRRELVM
    }
}

// MARK: - Weak<T>
private class Weak<T:AnyObject> {
    init(value: T) {
        self.value = value
    }
    
    weak var value: T?
}

infix operator ~ { associativity left precedence 140 }
prefix operator ~ {}

private func ~ (sqvm: HSQUIRRELVM, vm: SquirrelVM?) {
    if let vm = vm {
        var foreignPtr = UnsafeMutablePointer<Weak<SquirrelVM>>.alloc(1)
        foreignPtr.initialize(Weak(value: vm))
        sq_setforeignptr(sqvm, foreignPtr)
    }
    else {
        let foreignPtr = sq_getforeignptr(sqvm)
        if foreignPtr != nil {
            foreignPtr.destroy()
            foreignPtr.dealloc(1)
        }
    }
}

private prefix func ~ (vm: HSQUIRRELVM) -> SquirrelVM? {
    let ptr = sq_getforeignptr(vm)
    
    if ptr != nil {
        if let vm = UnsafeMutablePointer<Weak<SquirrelVM>>(ptr).memory.value {
            return vm;
        }
    }
    return nil
}
