-
I have gone through some modules (k8s, uuid, etc.). The common thing I observed is that functions were written that act as a bridge between the original go package and risor, which return a type of object (NewInt, FromGoType, etc.). It would be better If I got to know how these modules work or some hints so that I continue to see how things work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @roopeshsn, you're definitely on the right track. Luckily, there's really nothing magical about modules. As you've seen, the The Module type is implemented here: It's a simple implementation, with the 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 object then will contain multiple Builtin functions, as is the case with the func Module() *object.Module {
return object.NewBuiltinsModule("math", map[string]object.Object{
"abs": object.NewBuiltin("abs", Abs),
}
} |
Beta Was this translation helpful? Give feedback.
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 …