swiftwasm / JavaScriptKit

Swift framework to interact with JavaScript through WebAssembly.
https://swiftpackageindex.com/swiftwasm/JavaScriptKit/main/documentation/javascriptkit
MIT License
664 stars 44 forks source link

Are JSValue bitmasks possible? #220

Closed TeamPuzel closed 1 year ago

TeamPuzel commented 1 year ago

Hey, is it possible to use the OR operator somehow? I can call this webgl function:

context.clear(context.COLOR_BUFFER_BIT)

however this does not work:

context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT)
kateinoigakukun commented 1 year ago

Please cast JSValue to Int and apply OR in Swift, then pass it to JS method like below:

let COLOR_BUFFER_BIT = Int(context.COLOR_BUFFER_BIT.number!)
let DEPTH_BUFFER_BIT = Int(context.DEPTH_BUFFER_BIT.number!)
context.clear(COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT)
TeamPuzel commented 1 year ago

Thanks, I couldn't figure out the .number! part 🙂