-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
Wondering how I could create a working math.Pow(2,3) and math.Log(2).
I tried:
lib := make(map[string]interface{})
lib["Pow"] = math.Pow
sdict, err := convert.MakeStringDict(lib) // also doesn't work if we omit this
panicOn(err)
env.Starlark.GoGlobal["math"] = sdict
dict, err = convert.MakeStringDict(env.Starlark.GoGlobal)
panicOn(err)
// use dict as the globals in a call
but I get
Error: starlight_map<map[string]interface {}> has no .Pow field or method
or
Error: starlight_map<starlark.StringDict> has no .Pow field or method
ah. conv.go:48 has a TODO that indicates recursive maps aren't implemented.
update: also I've been doing too much Lua where this actually works and maps (tables) can act as packages (which makes sense since they are both just hash tables). Python doesn't like this syntax
Python 3.7.1 (default, Nov 6 2018, 18:45:35)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a={"b":2}
>>> a
{'b': 2}
>>> a.b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'b'
>>>
so some other way to represent packages is needed if python "use this package after import" is to be realized.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels