Matthew Butterick 7 years ago
parent 7272c8ad36
commit 95ac3bb1c0

@ -18,7 +18,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[(· ctx parent) => find-top-ctx] [(· ctx parent) => find-top-ctx]
[else ctx])) [else ctx]))
(define-subclass object% (Pointer offset-type type-in [options (mhasheq)]) (define-subclass RestructureBase (Pointer offset-type type-in [options (mhasheq)])
(field [type (and (not (eq? type-in 'void)) type-in)]) (field [type (and (not (eq? type-in 'void)) type-in)])
(define pointer-style (or (· options type) 'local)) (define pointer-style (or (· options type) 'local))
(define allow-null (or (· options allowNull) #t)) (define allow-null (or (· options allowNull) #t))
@ -26,7 +26,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(define lazy (· options lazy)) (define lazy (· options lazy))
(define relative-getter-or-0 (or (· options relativeTo) (λ (ctx) 0))) ; changed this to a simple lambda (define relative-getter-or-0 (or (· options relativeTo) (λ (ctx) 0))) ; changed this to a simple lambda
(define/public (decode stream [ctx #f]) (define/override (decode stream [ctx #f])
(define offset (send offset-type decode stream ctx)) (define offset (send offset-type decode stream ctx))
(cond (cond
[(and allow-null (= offset null-value)) #f] ; handle null pointers [(and allow-null (= offset null-value)) #f] ; handle null pointers
@ -56,7 +56,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[else ptr])])) [else ptr])]))
(define/public (size [val #f] [ctx #f]) (define/override (size [val #f] [ctx #f])
(let*-values ([(parent) ctx] (let*-values ([(parent) ctx]
[(ctx) (caseq pointer-style [(ctx) (caseq pointer-style
[(local immediate) ctx] [(local immediate) ctx]
@ -70,7 +70,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(send offset-type size))) (send offset-type size)))
(define/public (encode stream val [ctx #f]) (define/override (encode stream val [ctx #f])
(if (not val) (if (not val)
(send offset-type encode stream null-value) (send offset-type encode stream null-value)
(let* ([parent ctx] (let* ([parent ctx]

Loading…
Cancel
Save