Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate chaiscript file within a chaiscript file

Tags:

chaiscript

I'm starting to learn chaiscript and couldn't find this in the documentation.

I know there is API to evaluate a chaiscript file from C++ by calling ChaiScript::eval_file

But is it possible to do the same from a chaiscript file?

like image 397
user3750790 Avatar asked Mar 06 '26 14:03

user3750790


1 Answers

From within ChaiScript the use function is available, but the eval_file is not. use only loads a file if it has not already been loaded. eval_file loads the file regardless.

use("use.inc")

assert_equal("hello", greet())

// Include it a second time and see if there are any errors
use("use.inc")

assert_equal("hello", greet())

From here: https://github.com/ChaiScript/ChaiScript/blob/master/unittests/use.chai

Documentation of the C++ implementation of this function is here: http://chaiscript.com/docs/5/classchaiscript_1_1_chai_script.html#a9fc2eaf37274d09d1ee90ffd411e665c

I don't see any documentation specifying that it's also exposed to the ChaiScript runtime, but you can see many of the functions that are exposed here: https://github.com/ChaiScript/ChaiScript/blob/master/include/chaiscript/language/chaiscript_engine.hpp#L318

like image 55
lefticus Avatar answered Mar 09 '26 09:03

lefticus