FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gpython/examples/embedding/main.go at main · go-python/gpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
go-python
/
gpython
Public
Notifications
You must be signed in to change notification settings
Fork
105
Star
1k
Code
Issues
49
Pull requests
5
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gpython
/
examples
/
embedding
/
main.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (40 loc) · 1.23 KB
Breadcrumbs
gpython
/
examples
/
embedding
/
main.go
Copy path
File metadata and controls
54 lines (40 loc) · 1.23 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2022 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
import
(
"flag"
"fmt"
// This initializes gpython for runtime execution and is essential.
// It defines forward-declared symbols and registers native built-in modules, such as sys and time.
_
"github.com/go-python/gpython/stdlib"
// Commonly consumed gpython
"github.com/go-python/gpython/py"
"github.com/go-python/gpython/repl"
"github.com/go-python/gpython/repl/cli"
)
func
main
() {
flag
.
Parse
()
runWithFile
(
flag
.
Arg
(
0
))
}
func
runWithFile
(
pyFile
string
)
error
{
// See type Context interface and related docs
ctx
:=
py
.
NewContext
(
py
.
DefaultContextOpts
())
// This drives modules being able to perform cleanup and release resources
defer
ctx
.
Close
()
var
err
error
if
len
(
pyFile
)
==
0
{
replCtx
:=
repl
.
New
(
ctx
)
fmt
.
Print
(
"
\n
======= Entering REPL mode, press Ctrl+D to exit =======
\n
"
)
_
,
err
=
py
.
RunFile
(
ctx
,
"lib/REPL-startup.py"
, py.
CompileOpts
{},
replCtx
.
Module
)
if
err
==
nil
{
cli
.
RunREPL
(
replCtx
)
}
}
else
{
_
,
err
=
py
.
RunFile
(
ctx
,
pyFile
, py.
CompileOpts
{},
nil
)
}
if
err
!=
nil
{
py
.
TracebackDump
(
err
)
}
return
err
}
Back
|
FazBrowse Home
|
New Git URL