forked from flosch/GoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymodule.go
50 lines (41 loc) · 970 Bytes
/
pymodule.go
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
package vm
import (
"fmt"
)
type PyModule struct {
PyObjectData
module *Module
name *string
// If module is extern (it's own pyc file):
content *codeReader
code PyObject
interned_strings []PyObject
}
func (pm *PyModule) asString() *string {
str := fmt.Sprintf("<module %s>", *pm.name)
return &str
}
func (pm *PyModule) getValue() interface{} {
return nil
}
func (pm *PyModule) isTrue() bool {
return true
}
func NewPyModule(name *string) PyObject {
mod := new(PyModule)
mod.pyObjInit()
mod.name = name
// Import all functions and global names and make them
// available in the attributes
module, is_builtin := Modules[*name]
if is_builtin {
mod.module = &module
if err := module.inject(mod); err != nil {
panic("Error during module injection: " + err.Error())
}
} else {
// Search for a pyc file and execute it!
panic(fmt.Sprintf("Non-builtin modules are not supported yet (%v)", *name))
}
return mod
}