• Part 2

    But therein lies the problem. How to get at the block (#438) that contains what we are after when we only have reference to the String name (#428) that is the actual text identifying it's function.

    trace("dl") will locate it's referenced block #438, but I need what #438 points to, that is it's content, in this case block #428 the function itself, during runtime.

    In our cleaned up version, it is block #438 after locating #428

      #428[r1,l2] Name String [1 blocks] "dl"    #438[r1,l0] Function {
          #437[r1,l2] Name String [1 blocks] "\xFFcod"        #637[r1,l0] FlatString [150 blocks] "console.log( \"    \" );\n  console.log( \"JsVars  Last:\" );\n  console.log( \"  Free:   lastFree \" + lastFree );\n  console.log( \"  Usage:  lastUsage \" + lastUsage );\n  console.log( \"  History: 
    
    *** very large chunk removed for brevity ***
    
    lastHistory - gmh() ) + \"    last: \" + lastHistory + \"    cur: \" + gmh() );\n  console.log( \"    \" );\n  console.log( \"    \" );\n  console.log( process.memory() );\n\n\n  lastFree = gmf();\n  lastUsage = gmu();\n  lastHistory = gmh();"
          #434[r1,l2] Name String [1 blocks] "\xFFlin"= int 114
        }
    

    Using:

    http://www.espruino.com/Reference#l__global_trace
    http://www.espruino.com/Reference#l__global_global

    I learned that the global variable is just a Javascript Object after:

    >typeof global
    ="object"
    > 
    

    then creating an array that I can manipulate and assigning the contents of the global variable to the array object just created:

    >var aaa=[]
    =[  ]
    >aaa=global
    ={
      Graphics: function () { [native code] },
      g: Graphics: {
        flip: function () { [native code] }
       },
      testmem: {  },
      tm: function () { ... },
    
    . . .
    
    etc
    

    Using properties of that object, I am able to extract the data for a var I defined:

    >var aaa=[]
    =[  ]
    >aaa=global
    
    >aaa.num_str_vars
    =2
    

    That checks out and as expected.


    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

    Attempting to iterate using the entries method is fraught with errors:

    >for (let [key, value] of Object.entries(aaa)) {
    :  console.log(`${key}: ${value}`);
    :}
    Uncaught SyntaxError: Got '[' expected ';'
     at line 1 col 10
    for (let [key, value] of Object.entries(aaa)) {
             ^
    
    
    for ( let key of Object.entries(aaa)) {
    }
    Uncaught Error: Function "entries" not found!
     at line 1 col 25
    for ( let key of Object.entries(aaa)) {
    


    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

    global.forEach(element => console.log(element));
    
    Uncaught Error: Function "forEach" not found!
     at line 1 col 8
    global.forEach(element => console.log(element));
           ^
    

    Although I was able to iterate over the history array using just indexers into the array, the rest has become the big surprise, and not what I thought I could get done.



    For the curious onlookers:

    Please heed the code file internal Warning and read everything before uploading

    WARNING - Not for beginners or the impatient. Intended for individuals with intermediate to advanced skills. Will lock up the device it is installed on.

    Better yet, beginners please don't upload at all!


    2 Attachments

About

Avatar for Robin @Robin started