gluon icon indicating copy to clipboard operation
gluon copied to clipboard

It's not clear how to work with mutable rust state.

Open mikeando opened this issue 6 years ago • 1 comments

I'm interested in using gluon for scripting my rust application - but I can't see a way to work with mutable state on the rust side. Presumably, it involves some wrapping of the rust objects into a corresponding Action Monad, and then executing the results from within rust - but I can't seem to find a concrete example of this.

If someone can give me the outline I'd be happy to contribute some docs on how it can all work.

I've opened a stack-overflow question too: https://stackoverflow.com/q/54431243/221955

Thanks.

mikeando avatar Jan 29 '19 23:01 mikeando

So this isn't quite fleshed out in gluon yet, however the plan is to make it simple to define this via effects (and potentially by making custom monads if necessary). I want to get started on this fairly soon, likely the next thing I will work on (just been busy with cleanups and optimizing #679).

For the moment the easiest way would probably be to just ignore monads altogether, gluon does not (yet) make any assumptions about purity so plainly calling impure functions will just work. Alternatively you can run the code in the IO monad.

As for marshalling your data to gluon there is this example https://github.com/gluon-lang/gluon/blob/master/examples/marshalling.rs and the REPL https://github.com/gluon-lang/gluon/tree/master/repl/src (the REPL is likely where I will dog food the solution for this problem):

Marwes avatar Jan 30 '19 22:01 Marwes