Expand description
cpp style preprocessor
this can be used to define c-like preprocessing instructions in javascript
function do_stuff(input) {
#ifdef $GRECO_DEBUG
if (input.includes('booh')) {
throw Error('input should not include booh');
}
#endif
console.log('got input %s', input);
}
it used the gpp crate and docs on how it works are here https://docs.rs/gpp/0.6.0/gpp
by default GreenCopperRuntime conditionally sets the $GRECO_DEBUG, $GRECO_TEST and $GRECO_RELEASE
you can also add all current env_vars so in script you can use let path = "$PATH";
;
§Example
use green_copper_runtime::preprocessors::cpp::CppPreProcessor;
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use quickjs_runtime::jsutils::Script;
let cpp = CppPreProcessor::new().default_extensions().env_vars();
let rt = QuickJsRuntimeBuilder::new().script_pre_processor(cpp).build();
let path = rt.eval_sync(None, Script::new("test.js", "let p = '$PATH'; p")).ok().expect("script failed");
assert!(!path.get_str().is_empty());
assert_ne!(path.get_str(), "$PATH");