Skip to content

How do modules work? #191

Answered by myzie
roopeshsn asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @roopeshsn, you're definitely on the right track.

Luckily, there's really nothing magical about modules. As you've seen, the object.Object interface type in Risor is key. Risor's built-in types implement Object and similarly any new Go types you introduce that implement Object can easily be used in Risor.

The Module type is implemented here:
https://github.com/risor-io/risor/blob/main/object/module.go

It's a simple implementation, with the GetAttr method looking up fields contained by the module.

Functions in Risor implement Object as well, via the Builtin type and the Function type. The former is for wrapping Go functions, the latter is for compiled Risor functions.

Commonly a Module …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by roopeshsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants