llpyg => pydump
This commit is contained in:
@@ -20,35 +20,38 @@ import (
|
|||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
"github.com/goplus/llgo/py"
|
"github.com/goplus/llgo/py"
|
||||||
"github.com/goplus/llgo/py/inspect"
|
"github.com/goplus/llgo/py/inspect"
|
||||||
|
"github.com/goplus/llgo/x/cjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if c.Argc < 2 {
|
if c.Argc < 2 {
|
||||||
c.Fprintf(c.Stderr, c.Str("Usage: llpyg <pythonLibPath> [<destDir>]\n"))
|
c.Fprintf(c.Stderr, c.Str("Usage: pydump <pythonLibPath>\n"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pyLib := c.Index(c.Argv, 1)
|
pyLib := c.Index(c.Argv, 1)
|
||||||
destDir := c.Str(".")
|
|
||||||
if c.Argc > 2 {
|
|
||||||
destDir = c.Index(c.Argv, 2)
|
|
||||||
}
|
|
||||||
c.Fprintf(c.Stderr, c.Str("pyLib: %s, destDir: %s\n"), pyLib, destDir)
|
|
||||||
|
|
||||||
py.Initialize()
|
py.Initialize()
|
||||||
|
|
||||||
|
root := cjson.Object()
|
||||||
|
root.SetItem(c.Str("name"), cjson.String(pyLib))
|
||||||
|
|
||||||
|
items := cjson.Array()
|
||||||
mod := py.ImportModule(pyLib)
|
mod := py.ImportModule(pyLib)
|
||||||
keys := mod.ModuleGetDict().DictKeys()
|
keys := mod.ModuleGetDict().DictKeys()
|
||||||
for i, n := uintptr(0), keys.ListLen(); i < n; i++ {
|
for i, n := uintptr(0), keys.ListLen(); i < n; i++ {
|
||||||
key := keys.ListItem(i)
|
key := keys.ListItem(i)
|
||||||
val := mod.GetAttr(key)
|
val := mod.GetAttr(key)
|
||||||
doc := val.GetAttrString(c.Str("__doc__"))
|
doc := val.GetAttrString(c.Str("__doc__"))
|
||||||
c.Fprintf(c.Stderr, c.Str("-----------------------------------\n"))
|
sym := cjson.Object()
|
||||||
if val.Callable() != 0 {
|
sym.SetItem(c.Str("name"), cjson.String(key.CStr()))
|
||||||
|
sym.SetItem(c.Str("doc"), cjson.String(doc.CStr()))
|
||||||
|
if val.Callable() != 0 && false {
|
||||||
sig := inspect.Signature(val)
|
sig := inspect.Signature(val)
|
||||||
c.Fprintf(c.Stderr, c.Str("%s: %s\n"), key.CStr(), sig.Str().CStr())
|
sym.SetItem(c.Str("sig"), cjson.String(sig.Str().CStr()))
|
||||||
} else {
|
|
||||||
c.Fprintf(c.Stderr, c.Str("var: %s\n"), key.CStr())
|
|
||||||
}
|
}
|
||||||
c.Fprintf(c.Stderr, c.Str("%s\n"), doc.CStr())
|
items.AddItem(sym)
|
||||||
}
|
}
|
||||||
|
root.SetItem(c.Str("items"), items)
|
||||||
|
|
||||||
|
c.Printf(c.Str("%s\n"), root.CStr())
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user