[SOLVED] What is the API of emScript when dealing with javascript language?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] What is the API of emScript when dealing with javascript language?

    Hello Segger staff,


    I have a techinnical inquiry regarding to the emScript.exe that is included in Segger Embedded Studio.


    I would like to know what kind of javascript version is being used in the emScript.exe interpreter. I am interested in knowing that becuase I need to know what kind of method I can use or not. For instance, I do know making usage of the method search() in a string will turn into an 'undefined' error, which to me means that that method seems not to be implemented.


    Therefore, I would like you to tell me the API that is implemented in emScript.exe in order to cope with javascript files.


    Finally, I instance you to try to run the below code snippet in Embedded Studio using emScript to check that the method search() for strings (amongst other) is not implemented or understood by emScript.exe. It will compile without error but the execution/ouput is wrong.


    Looking forward to hearing from you,


    Kind regards




    Code:

    JavaScript Source Code

    1. var myLog = "log.txt"
    2. var example = "Example_for_emScript";
    3. CWSys.writeStringToFile(myLog, "--Starting emScript method test--"+"\n")
    4. //These two examples will fail because the return value of the call example.search() is undefined, which is wrong since
    5. // javascript implements the method search to search string within strings. See https://www.w3schools.com/Jsref/jsref_search.asp
    6. CWSys.appendStringToFile(myLog, "example.search(emScript) ouput->"+example.search("emScript")+", output should be 12"+"\n")
    7. CWSys.appendStringToFile(myLog, "example.search(for) output->"+example.search("for")+"output should be 8"+"\n")
    8. //None of the following strings will be appended to log.txt since the output of search is undefined...
    9. if( example.search("emScript") >-1 ){
    10. CWSys.appendStringToFile(myLog, "emScript string was found!"+"\n")
    11. } else if (example.search("for") >-1) {
    12. CWSys.appendStringToFile(myLog, "for string was found!"+"\n")
    13. }
    14. CWSys.appendStringToFile(myLog, "--Finishing emScript method test--"+"\n")
    Display All
  • Hello,

    Thank you for your inquiry.
    Supported is ECMAScript 3rd edition.
    In your code snippet you are using regular expressions which are not supported/implemented.
    We will discuss internally if they can be added for future versions.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Nino wrote:

    In your code snippet you are using regular expressions which are not supported/implemented.
    Hi Nino,

    Thanks for replying.

    I have to disagree, in my code snippet I am not using regular expresions I am using just strings, you see that I am defining the strings with double colons ("for" , "emScript").Whereas the regular expresions should start or with slashes or calling constructor RegExp(). And as I comented, looking for the search() method shows that it can handle strings and regular expresions.

    Definition and Usage
    The search() method searches a string for a specified value, and returns the position of the match.
    The search value can be string or a regular expression.
    This method returns -1 if no match is found.
    Read more about regular expressions in our RegExp Tutorial and our RegExp Object Reference.


    Could you tell me then how I can search for certain substring within a string? Let's say that in my string Example_for_emScript I would like to search for the substring emScript. How should I do that?


    Thanks again,


    Regards
  • Hello,

    I should rephrase that.
    match/replace/search are not supported/implemented in the current Embedded Studio release.
    A non-regexp versionis planned be supported in the next release.


    Sorry for any inconveniences caused.


    Best regards,

    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Nino wrote:

    I should rephrase that.
    match/replace/search are not supported/implemented in the current Embedded Studio release.
    A non-regexp versionis planned be supported in the next release.


    Sorry for any inconveniences caused.
    Thanks Nino,

    Now I understand, I will try to figure it out in a different way.

    Regards