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
420bdcda
Commit
420bdcda
authored
Apr 25, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add hasitem and hasattr to Py proxy
parent
ced8597f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletion
+19
-1
src/main.cpp
src/main.cpp
+3
-1
src/pyproxy.cpp
src/pyproxy.cpp
+14
-0
src/pyproxy.hpp
src/pyproxy.hpp
+2
-0
No files found.
src/main.cpp
View file @
420bdcda
...
...
@@ -42,8 +42,10 @@ EMSCRIPTEN_BINDINGS(python) {
.
function
<
val
>
(
"call"
,
&
Py
::
call
)
.
function
<
val
>
(
"getattr"
,
&
Py
::
getattr
)
.
function
<
void
>
(
"setattr"
,
&
Py
::
setattr
)
.
function
<
val
>
(
"hasattr"
,
&
Py
::
hasattr
)
.
function
<
val
>
(
"getitem"
,
&
Py
::
getitem
)
.
function
<
void
>
(
"setitem"
,
&
Py
::
setitem
);
.
function
<
void
>
(
"setitem"
,
&
Py
::
setitem
)
.
function
<
val
>
(
"hasitem"
,
&
Py
::
hasitem
);
}
extern
"C"
{
...
...
src/pyproxy.cpp
View file @
420bdcda
...
...
@@ -63,6 +63,13 @@ void Py::setattr(val idx, val v) {
}
}
val
Py
::
hasattr
(
val
idx
)
{
PyObject
*
pyidx
=
jsToPython
(
idx
);
val
result
(
PyObject_HasAttr
(
x
,
pyidx
)
?
true
:
false
);
Py_DECREF
(
pyidx
);
return
result
;
}
val
Py
::
getitem
(
val
idx
)
{
PyObject
*
pyidx
=
jsToPython
(
idx
);
PyObject
*
item
=
PyObject_GetItem
(
x
,
pyidx
);
...
...
@@ -87,3 +94,10 @@ void Py::setitem(val idx, val v) {
pythonExcToJs
();
}
}
val
Py
::
hasitem
(
val
idx
)
{
PyObject
*
pyidx
=
jsToPython
(
idx
);
val
result
(
PySequence_Contains
(
x
,
pyidx
)
?
true
:
false
);
Py_DECREF
(
pyidx
);
return
result
;
}
src/pyproxy.hpp
View file @
420bdcda
...
...
@@ -20,8 +20,10 @@ public:
emscripten
::
val
call
(
emscripten
::
val
args
,
emscripten
::
val
kwargs
);
emscripten
::
val
getattr
(
emscripten
::
val
idx
);
void
setattr
(
emscripten
::
val
idx
,
emscripten
::
val
v
);
emscripten
::
val
hasattr
(
emscripten
::
val
idx
);
emscripten
::
val
getitem
(
emscripten
::
val
idx
);
void
setitem
(
emscripten
::
val
idx
,
emscripten
::
val
v
);
emscripten
::
val
hasitem
(
emscripten
::
val
idx
);
};
#endif
/* PYPROXY_H */
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