Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on how to use modules #555

Open
jayaprabhakar opened this issue May 21, 2024 · 1 comment
Open

Documentation on how to use modules #555

jayaprabhakar opened this issue May 21, 2024 · 1 comment

Comments

@jayaprabhakar
Copy link

I see a number of modules defined in https://github.com/google/starlark-go/tree/master/starlark/testdata,
But I am not sure how to use those modules, I'm primarily looking for the math module.

Similarly, I see another math module in the starlark-go code: https://github.com/google/starlark-go/tree/master/lib/math
Again, I couldn't find any documentation how to use it.

It would be also be nice, to have at least one example on how to use starlarkstruct.Module to define a new module and use them as well.

@jayaprabhakar
Copy link
Author

I found how to use the modules defined in go using starlarkstruct.Module.

For example: To use the math module defined in https://github.com/google/starlark-go/tree/master/lib/math
just add it to the globals.

globals := starlark.StringDict{
	"math":  math.Module,
}

Then, in the starlark code, you can simply use,

print(math.ceil(3.5))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant