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

is there any way to serialize and deserialize rhai ast from and to string? #547

Closed
OfekShochat opened this issue Apr 1, 2022 · 2 comments

Comments

@OfekShochat
Copy link

hello! Im trying to cache asts but I don't see any way to do this. I don't think #161 is finished, but idk. is there any standard way of doing this or should I try and take all the info and then reconstruct the ast?
thanks!
ps great project

@schungx
Copy link
Collaborator

schungx commented Apr 1, 2022

Well, I actually tried something like this in my on fork, in a branch called ast_serde. It is very old though.

https://github.com/schungx/rhai/tree/ast_serde

At half ways, I realized that there really is no point in doing this, as persisting the original script is easier and quicker than generating a string serialization from an AST.

Therefore, the standard way is to persist the script text itself (which can be compressed easily if you're really pressed for space).

Parsing is reasonably fast so text -> AST shouldn't be a problem if you do it every time. It is certainly not going to be more costly than deserializing with serde.

@OfekShochat
Copy link
Author

OfekShochat commented Apr 1, 2022

sure, cool (not going to deserialize it every time tho, I have a cache that is initialized from a db)

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

2 participants