'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?
'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)
The typeof operator can return one of two complex types:
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
applyto work, so we can do:
The problem I am having is knowing if
moveare 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
getcalls 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/EspruinoWebTools/blob/13032d0e862d9976ed5eed33b42f07e93e6c25c3/uart.js#L491-L497
Also I implemented a simple promise system on top of eval, works very well!