-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javascript additional functionality #4603
Javascript additional functionality #4603
Conversation
9e0d75e
to
ee752f6
Compare
This adds a simple two way Python to JS bridge and a HTML browser example that demonstrates MicroPython in the browser.
ee752f6
to
6151b5f
Compare
I guess you were referring to the commit message style? Changed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, it makes it more usable. Please see comments in the PR.
@@ -36,6 +36,7 @@ SRC_C = \ | |||
main.c \ | |||
mphalport.c \ | |||
modutime.c \ | |||
js_module.c \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following how it's done elsewhere, this should be called modjs.c
@@ -7,16 +7,16 @@ Dependencies | |||
------------ | |||
|
|||
Building micropython.js bears the same requirements as the standard MicroPython | |||
ports with the addition of Emscripten (and uglify-js for the minified file). | |||
ports with the addition of Emscripten (and uglify-js for the minified file). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, unrelated changes like fixing things like this whitespace would be done in separate commits, to keep changes self contained and easier to review/understand.
@@ -0,0 +1,5 @@ | |||
import js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file needed at all? If so (as a simple example) it should probably go in the examples/ dir, under a new examples/javascript/ subdir.
|
||
// forward declare emscripten stuff | ||
void emscripten_run_script(const char *); | ||
int emscripten_run_script_int(const char *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does emscripten have a header file for these?
return mp_const_none; | ||
} | ||
|
||
STATIC mp_obj_t js_evali(mp_obj_t js_string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other return types that could be supported, like float? They don't have to be added now, but good to think how they would be consistently named (eg evalf) if they were added in the future.
if (__initBrowserCount == 0) | ||
{ | ||
var mp_js_stdout = document.getElementById('mp_js_stdout'); | ||
mp_js_stdout.addEventListener('print', function(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason this was done in the html before is so it can be customised for the particular use/app. I guess this default behaviour can still be overridden by a particular app, by changing the event listener?
} | ||
}, false); | ||
|
||
mp_js_init(64 * 1024); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done in the html previously so it could be changed based on need of the app, eg made bigger or smaller. How could it be made customisable?
{ | ||
mp_js_do_str(document.scripts[i].innerText); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the same coding/brace style as already exists in this file.
…n-main Translations update from Weblate
Closing due to inactivity. Feel free to reopen with review comments addressed. |
This adds some functionality to the Javascript port:
<script type="script/micropython">
tags and executes themmake server
which builds and shows thetest.html
webpage to see a small example of micropython functionality in the browser