You are reading a single comment by @Robin and its replies. Click here to read the full conversation.
  • I am banging my head trying to make proxy work for all cases which seems very hard, if not impossible. Ideally I would like both get, set, and apply to work, so we can do:

    robot = EspruinoDevice(UART) 
    var p = await robot.speed;  // assuming speed is a variable defined on the repl
    var temp = await robot.getTemperature() // assuming getTemperature() is defined on the repl
    await robot.move(someparameters)
    await robot.speed = 2*p; // changing the speed variable
    

    The problem I am having is knowing if speed or move are object or function which change the expected behaviour from the proxy. I tried many approaches, but I start to feel it is impossible because we can only know if it is a function or the object after we return something and see if it is later called as a function again. I then tried to go via promises to see if I could decide this later but the same problem came back in the end. I am running short of ideas right now.

    Some ressources I used:

    I am quite stuck so I will stop now. I am aware all can be solved by relying on setter and getter function on the device, e.g getSpeed() and setSpeed(), and then building the proxy assuming all get calls are function calls. But I enjoy the challenge, it would be so neat to get all cases working seamlessly.

    Any thoughts on this?

    As an alternative route, is there a method to list all user defined variable and function on the Espruino device? That way we could ask for that list when connecting and decide what can and cannot be called.

    ==

    One learning to maybe add to the issue -> it would be good to have the eval function return 'undefined' when it receives 'undefined' (right now it catch an error, print it, and call the cb with null instead). This way we can use eval for all actions and know if it actually crashed or ran well but got undefined back. That would be around here: https://github.com/espruino/EspruinoWebT­ools/blob/13032d0e862d9976ed5eed33b42f07­e93e6c25c3/uart.js#L491-L497

    Also I implemented a simple promise system on top of eval, works very well!

  • Sat 2021.04.24

    'is there a method to list all user defined variable and function on the Espruino device?'

    I presume after upload to the device? Will dump() do the trick?

    http://www.espruino.com/Reference#l__glo­bal_dump


    'but I start to feel it is impossible because we can only know if it is a function or the object after we return something and see if it is later called as a function again'

    Honestly @jgrizou, I'm not sure I understand the dilemma, is this what you are after?

    See Heading 'Complex Data' (near end of page)

    https://www.w3schools.com/js/js_datatype­s.asp
    The typeof operator can return one of two complex types:
    function
    object

About

Avatar for Robin @Robin started