Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
d7e4cb8a
Commit
d7e4cb8a
authored
Mar 07, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convenient access to repr() on the Javascript side
parent
8e3e3608
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
src/js2python.cpp
src/js2python.cpp
+9
-1
src/main.cpp
src/main.cpp
+15
-0
src/pyproxy.hpp
src/pyproxy.hpp
+1
-1
No files found.
src/js2python.cpp
View file @
d7e4cb8a
#include "js2python.hpp"
#include "jsproxy.hpp"
#include "pyproxy.hpp"
using
emscripten
::
val
;
...
...
@@ -20,7 +21,14 @@ PyObject *jsToPython(val x) {
Py_INCREF
(
Py_None
);
return
Py_None
;
}
else
{
return
JsProxy_cnew
(
x
);
try
{
Py
py_x
=
x
.
as
<
Py
>
();
PyObject
*
pypy_x
=
py_x
.
x
;
Py_INCREF
(
pypy_x
);
return
pypy_x
;
}
catch
(...)
{
return
JsProxy_cnew
(
x
);
}
}
}
...
...
src/main.cpp
View file @
d7e4cb8a
...
...
@@ -21,9 +21,24 @@ using emscripten::val;
// Conversions
val
repr
(
val
v
)
{
PyObject
*
pyv
=
jsToPython
(
v
);
PyObject
*
r
=
PyObject_Repr
(
pyv
);
if
(
r
==
NULL
)
{
return
pythonExcToJs
();
}
PyObject_Print
(
r
,
0
,
0
);
val
result
=
pythonToJs
(
r
);
Py_DECREF
(
r
);
Py_DECREF
(
pyv
);
return
result
;
}
EMSCRIPTEN_BINDINGS
(
python
)
{
emscripten
::
function
(
"runPython"
,
&
runPython
);
emscripten
::
function
(
"pyimport"
,
&
pyimport
);
emscripten
::
function
(
"repr"
,
&
repr
);
emscripten
::
class_
<
Py
>
(
"Py"
)
.
function
<
val
>
(
"call"
,
&
Py
::
call
)
.
function
<
val
>
(
"getattr"
,
&
Py
::
getattr
)
...
...
src/pyproxy.hpp
View file @
d7e4cb8a
...
...
@@ -10,9 +10,9 @@
#include "python2js.hpp"
class
Py
{
public:
PyObject
*
x
;
public:
Py
(
PyObject
*
obj
);
Py
(
const
Py
&
o
);
~
Py
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment