FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RustPython/examples/package_embed.rs at main · RustPython/RustPython · GitHub
RustPython
RustPython
Repository navigation
Code
Issues
185
(185)
Pull requests
113
(113)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
RustPython
/
examples
/
package_embed.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (28 loc) · 1.09 KB
Breadcrumbs
RustPython
/
examples
/
package_embed.rs
Copy path
File metadata and controls
30 lines (28 loc) · 1.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use
rustpython_vm
as
vm
;
use
std
::
process
::
ExitCode
;
use
vm
::
{
Interpreter
,
builtins
::
PyStrRef
}
;
fn
py_main
(
interp
:
&
Interpreter
)
-> vm
::
PyResult
<
PyStrRef
>
{
interp
.
enter
(
|vm|
{
// Add local library path
vm
.
insert_sys_path
(
vm
.
new_pyobj
(
"examples"
)
)
.
expect
(
"add examples to sys.path failed"
)
;
let
module = vm
.
import
(
"package_embed"
,
0
)
?
;
let
name_func = module
.
get_attr
(
"context"
,
vm
)
?
;
let
result = name_func
.
call
(
(
)
,
vm
)
?
;
let
result
:
PyStrRef
= result
.
get_attr
(
"name"
,
vm
)
?
.
try_into_value
(
vm
)
?
;
vm
::
PyResult
::
Ok
(
result
)
}
)
}
fn
main
(
)
->
ExitCode
{
// Add standard library path
let
mut
settings = vm
::
Settings
::
default
(
)
;
settings
.
path_list
.
push
(
"Lib"
.
to_owned
(
)
)
;
let
builder = vm
::
Interpreter
::
builder
(
settings
)
;
let
defs = rustpython_stdlib
::
stdlib_module_defs
(
&
builder
.
ctx
)
;
let
interp = builder
.
add_native_modules
(
&
defs
)
.
build
(
)
;
let
result =
py_main
(
&
interp
)
;
let
result = result
.
map
(
|result|
{
println
!
(
"name: {result}"
)
;
}
)
;
vm
::
host_env
::
os
::
exit_code
(
interp
.
run
(
|_vm| result
)
)
}
Back
|
FazBrowse Home
|
New Git URL