Skip to content

Fixes issue with wrong numbers printing to console in csound for iOS #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions book/12-d-csound-in-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,19 +1008,16 @@ The process demonstrated in the code examples below can be described as:
}
```

Note that in Swift, we have to create a `CVaListPointer` (equivalent to a
`va_list *` in C) for use with the `vsnprintf()` function:


```swift
// Swift
func messageCallback(_ infoObj: NSValue) {
var info = Message()
infoObj.getValue(&info)
let message = UnsafeMutablePointer<Int8>.allocate(capacity: 1024)
let va_ptr: CVaListPointer = CVaListPointer(
_fromUnsafeMutablePointer: &(info.valist)
)
vsnprintf(message, 1024, info.format, va_ptr)

vsnprintf(message, 1024, info.format, info.valist)
let messageStr = String(cString: message)
print(messageStr)
Copy link
Author

@jase5 jase5 Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the memory for buffer should be deallocated in the end to prevent excessive memory use:
message?.deallocate()

}
Expand Down