Module creation at runtime #749
Replies: 6 comments
-
Posted at 2017-09-05 by @MaBecker what about this?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-05 by @gfwilliams Yes - it's not well documented, but adding by function is really neat and tidy. No need to name the function So you're saying that multi-line strings work, but just give the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-05 by @allObjects @mabe, indeed, after all, it is just a map or dictionary with a key and an object. I went for the string for several reasons:
In conversation about Module Development I went a step further: compose a module from module components - not only to avoid possible out of memory condition, but also pull most recent and on demand what is required by the application. (A similar pattern to bootloader: application bootloader). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-05 by @gfwilliams It's worth noting that:
and
are exactly the same code - so it's the same module pattern. It's just easier to write as a function because you don't get the acorn error and you also get syntax highlighting |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-05 by @allObjects @gordon, that's excellent... in other words, Therefore, instead of using concatenated or multi-line string to pass in the module source, the module 'source' is wrapped with an (anonymous) function that sets or populates the I will use this function approach to replace the string approach in mentioned conversation about Module Development. It fulfills exactly the same requirements I have with a better support. Syntax highlighting and (Espruino extended,) specific code completion are just two - important - parts of it, all provided by the Espruino IDE. ...all with enabling all sorts of makers in mind. (@gordon, is that - or at least a major port of it - not what ignited the Espruino-Journey in the first place?) PS: it's about time for me to really really dig into the Espruino source code... or not... I'm confused... ;-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-05 by @gfwilliams
Yes, that's the one! The idea is that if it's enabled, when you upload with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-04 by @allObjects
I try to use
Modules.addCached("moduleId","moduleSourceCode");
with"moduleCode
" as ES6 multi-line string (which is supported by Espruino) and as 'plain' concatenated string.The "moduleCode" can be part of the code or retrieved over communication (from Web) and enables maintaining self-updating code centrally for connected applications.
In below code I create a Person 'class'/prototype in module with same name 'on the go', which I later in the code use with
require("Person");
.Note: The
setTimeout(onInit, 1000);
is there for two reasons. First, I do not need to manually start theonInit()
in the console pane, and second, thesetTimeout()
lets the upload finish before starting the runtime part of the code.Despite the
Acorn parse ....failed....
error message it works. (see attached screen shot).I also get the
Module Person not found
warning message, which is expected.Both the error and warning messages are created by the upload as expected.
The lines 4..19 stored in
Person.js
file or minified inPerson.min.js
file and placed in.../modules
folder of my sandbox (see IDE settings - Project) work perfectly.I tried multiple variations to get over the error message, including using a 'plain' concatenated string (as below). Using the code in concatenated string needs though one of two changes:
Change 1: join strings with line feed (\n) delimiter. This terminates the line comments (//):
Change 2: change line comments (//) int block comments (/* ... */):
Without either one change, I get error message message in console, I get error on usage:
Multi-line string usage makes me suspicious.
What should I change to make the multi-line string work?
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions