chickadee » jiffi » struct-setter

(struct-setter ...) → proceduresyntax

Expands to an anonymous procedure that sets a struct field value.

Usage:

(struct-setter
 (ARMOR-NAME "STRUCT_NAME" PRED UNWRAP)
 FIELD-NAME
 type: FOREIGN-TYPE
 conv: S-CONV            ; optional
 name: NAME)             ; optional

NAME is an expression that evaluates to the procedure name (usually a symbol) to show in error messages if the struct cannot be unwrapped. If NAME is omitted or #f, error messages will not include a procedure name.

See define-struct-accessors for the meaning of the other macro arguments.

The procedure will behave similar to this pseudo-code:

(lambda (struct value)
  (let ((ptr (UNWRAP struct NAME)))
    (if S-CONV
        (set-field ptr FIELD-NAME (S-CONV value))
        (set-field ptr FIELD-NAME value))))

Example:

(set! (setter key-event-code)
      (struct-setter
       (key-event "FOO_Event" key-event? unwrap-key-event)
       "key.code"
       type: int
       conv: keycode->int
       name: 'key-event-code))