Skip to content
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

Closed

Conversation

wolfv
Copy link
Contributor

@wolfv wolfv commented Mar 13, 2019

This adds some functionality to the Javascript port:

  • two way JS <-> Python communication using a js module in Python and emscripten eval / evali functionality
  • adds code to wrapper.js to initialize the browser correctly, and find all <script type="script/micropython"> tags and executes them
  • another make target make server which builds and shows the test.html webpage to see a small example of micropython functionality in the browser

@wolfv wolfv force-pushed the javascript_additional_functionality branch from 9e0d75e to ee752f6 Compare March 13, 2019 18:04
@pfalcon
Copy link
Contributor

pfalcon commented Mar 13, 2019

This adds a simple two way Python to JS bridge and a HTML
browser example that demonstrates MicroPython in the browser.
@wolfv wolfv force-pushed the javascript_additional_functionality branch from ee752f6 to 6151b5f Compare March 14, 2019 15:49
@wolfv
Copy link
Contributor Author

wolfv commented Mar 14, 2019

I guess you were referring to the commit message style? Changed it.

Copy link
Member

@dpgeorge dpgeorge left a 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 \
Copy link
Member

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).
Copy link
Member

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
Copy link
Member

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 *);
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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);
}
}
Copy link
Member

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.

tannewt added a commit to tannewt/circuitpython that referenced this pull request Apr 16, 2021
@dpgeorge
Copy link
Member

Closing due to inactivity. Feel free to reopen with review comments addressed.

@dpgeorge dpgeorge closed this Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants