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

When does Chaiscript parse files? #597

Open
StandingPadAnimations opened this issue Jul 19, 2022 · 5 comments
Open

When does Chaiscript parse files? #597

StandingPadAnimations opened this issue Jul 19, 2022 · 5 comments

Comments

@StandingPadAnimations
Copy link

So when using Chaiscript with C++, when are the files parsed? Is it at compile time or runtime?

@totalgee
Copy link
Contributor

Chaiscript code/files are parsed and evaluated at runtime.

@StandingPadAnimations
Copy link
Author

Is there any sort of caching to avoid parsing multiple times?

@totalgee
Copy link
Contributor

From Chaiscript code, if you write use("file") instead of eval_file("file"), then it will only evaluate "file" once.

@SirNate0
Copy link
Contributor

Is there a way to get chai script to parse the code once but evaluate it multiple times? Say if I change some global variable x between executions and I eval("x+42")?

@totalgee
Copy link
Contributor

Make the Chaiscript code you eval return a function (fun() { /* do something */ }), store that function (lambda) in a variable, and then execute the function whenever you want to.

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

3 participants