-
Notifications
You must be signed in to change notification settings - Fork 773
add a scope class to manage the context of interaction with Python an… #381
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
Changes from 1 commit
8e0b1a2
72003aa
efd3798
9f50e25
add5ba8
c15555c
b0d57e9
ceaaef0
dec39c7
e117d60
904d9ed
5484451
2e063c2
dd492f4
df6a49a
f35d75b
497d7aa
60ce28b
ebf5a2b
2c3db3d
30543eb
b9dcdac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,12 @@ internal PyScope(string name) | |
| variables, "__builtins__", | ||
| Runtime.PyEval_GetBuiltins() | ||
| ); | ||
| InitVariables(); | ||
| } | ||
|
|
||
| //To compitable with the python module | ||
| private void InitVariables() | ||
| { | ||
| SetVariable("locals", (Func<PyDict>)Variables); | ||
| SetVariable("globals", (Func<PyDict>)Variables); | ||
| } | ||
|
|
@@ -50,10 +56,19 @@ internal PyScope(string name) | |
| /// </summary> | ||
| internal IntPtr variables { get; private set; } | ||
|
|
||
| public long Refcount | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this one for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used for debug, now there are 2 IntPtr in the PyScope and the code seems stable, so it was removed. |
||
| { | ||
| get | ||
| { | ||
| return Runtime.Refcount(variables); | ||
| } | ||
| } | ||
|
|
||
| public event Action<PyScope> OnDispose; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the use-case for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PyScopes are managed by Py class, when it was disposed, Py class can do some cleaning work through registering this event. In the future, methods in Py class maybe put in an independent ScopeManager class, see the responses below. |
||
|
|
||
| public PyDict Variables() | ||
| { | ||
| Runtime.XIncref(variables); | ||
| return new PyDict(variables); | ||
| } | ||
|
|
||
|
|
@@ -77,6 +92,7 @@ public void ImportScope(PyScope scope) | |
| { | ||
| throw new PythonException(); | ||
| } | ||
| InitVariables(); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
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.
As said before, I'm strongly against this. I don't see any advantage in this over separating
globalsandlocalsas done in the Python API.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.
See the responses below.