Help with using stdweb:: js!


#1

The JS code I care about is here: https://developer.mozilla.org/en-US/docs/Web/API/EXT_blend_minmax

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?


#2

Use a string instead of an invalid character literal?

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

#3

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)


#4

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


#5

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.


#6

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


#7

That makes sense.

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