Help with using stdweb:: js!

The JS code I care about is here: EXT_blend_minmax - Web APIs | MDN

The fragment I care about is:

var ext = gl.getExtension('EXT_blend_minmax');

gl.blendEquation(ext.MIN_EXT);
gl.blendEquation(ext.MAX_EXT);

gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);

what I have tried so far is:

        js! {
          var ext = gl.getExtension('EXT_blend_minmax');
          gl.blendEquation(ext.MAX_EXT);
        }

The error I get is:

error: character literal may only contain one codepoint: 'EXT_blend_minmax'
   |
40 |           var ext = gl.getExtension('EXT_blend_minmax');
   |                                     ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

My question is: how do I fix this?

Use a string instead of an invalid character literal?

var ext = gl.getExtension("EXT_blend_minmax");
2 Likes

Remember that rust is not js however you slice it, so 'a' is char and "abc" is &'static str. 'abc' is not allowed because it's supposed to be a char (single character) and not a string (str or any reference to it)

Wait ... so in js! { .... }
is the stuff in ... tokenized as Rust code,
then we do a List<Rust_Token> => List<JS_Token> conversion?

Embeds JavaScript code into your Rust program.

Please note my use of italics on Embeds, it basically converts it into rust. In other words; js! is, from what I can gather, a JsTokenList => RustTokenList converter. Just use double quotes if possible, or write a macro to convert it.

Macros cannot contain anything that is lexically invalid as Rust code. Otherwise, how would the compiler parse them?

3 Likes

That makes sense.

A change in point of view is worth 80 IQ points. :slight_smile:

1 Like