mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
committed by
GitHub
parent
6df5905b2b
commit
bccd5e3750
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<title>Plugins</title>
|
||||
<style>
|
||||
py-script {
|
||||
mpy-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -13,9 +13,10 @@
|
||||
{ "imports": { "@pyscript/core": "../../min.js" } }
|
||||
</script>
|
||||
<script type="module">
|
||||
import { registerPlugin } from "@pyscript/core";
|
||||
registerPlugin("mpy-script", {
|
||||
type: "micropython",
|
||||
import { define, whenDefined } from "@pyscript/core";
|
||||
whenDefined("mpy").then(console.log);
|
||||
define("mpy", {
|
||||
interpreter: "micropython",
|
||||
async onRuntimeReady(micropython, element) {
|
||||
console.log(micropython);
|
||||
// Somehow this doesn't work in MicroPython
|
||||
@@ -25,11 +26,21 @@
|
||||
micropython.run(element.textContent);
|
||||
element.replaceChildren("See console ->");
|
||||
element.style.display = "block";
|
||||
|
||||
const button = document.createElement("button");
|
||||
button.textContent = "click";
|
||||
button.setAttribute("mpy-click", "test_click(event)");
|
||||
document.body.append(button);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<mpy-script> print('Hello Console!') </mpy-script>
|
||||
<mpy-script mpy-click="test_click(event)">
|
||||
def test_click(event):
|
||||
print(event.type)
|
||||
|
||||
print('Hello Console!')
|
||||
</mpy-script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<title>Plugins</title>
|
||||
<style>
|
||||
py-script {
|
||||
lua-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -13,9 +13,9 @@
|
||||
{ "imports": { "@pyscript/core": "../../min.js" } }
|
||||
</script>
|
||||
<script type="module">
|
||||
import { registerPlugin } from "@pyscript/core";
|
||||
registerPlugin("lua-script", {
|
||||
type: "wasmoon",
|
||||
import { define } from "@pyscript/core";
|
||||
define("lua", {
|
||||
interpreter: "wasmoon",
|
||||
async onRuntimeReady(wasmoon, element) {
|
||||
// Somehow this doesn't work in Wasmoon
|
||||
wasmoon.io.stdout = (message) => {
|
||||
@@ -29,6 +29,8 @@
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<lua-script> print('Hello Console!') </lua-script>
|
||||
<lua-script lua-click="print(event.type)">
|
||||
print('Hello Console!')
|
||||
</lua-script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { registerPlugin } from "@pyscript/core";
|
||||
import { define } from "@pyscript/core";
|
||||
|
||||
// append ASAP CSS to avoid showing content
|
||||
document.head.appendChild(document.createElement("style")).textContent = `
|
||||
@@ -17,9 +17,9 @@ let bootstrap = true,
|
||||
const sharedPyodide = new Promise((resolve) => {
|
||||
const pyConfig = document.querySelector("py-config");
|
||||
const config = pyConfig?.getAttribute("src") || pyConfig?.textContent;
|
||||
registerPlugin("py-script", {
|
||||
define("py", {
|
||||
config,
|
||||
type: "pyodide",
|
||||
interpreter: "pyodide",
|
||||
codeBeforeRunWorker: `print('codeBeforeRunWorker')`,
|
||||
codeAfterRunWorker: `print('codeAfterRunWorker')`,
|
||||
onBeforeRun(pyodide, node) {
|
||||
|
||||
Reference in New Issue
Block a user