I would strongly recommend using a different name (say execscript
), which you can add to the scope you execute the user scripts in:
scope.SetVariable("execscript", (CodeContext context, string filename) => {
Builtins.execfile(context, Patch.Combine("../../Scripts", filename));
});
That will make it appear as a builtin without mucking with the builtins dictionary.
If it has to be execfile
, your best bet is going to be to replace the execfile
builtin with one that patches up the directory and then calls into the old execfile
. Here's some completely untested, uncompiled code that should point you in the right direction:
var engine = Python.CreateEngine();
var builtins = engine.GetBuiltinModule();
builtins.SetVariable("execfile", (CodeContext context, string filename) => {
Builtins.execfile(context, Patch.Combine("../../Scripts", filename));
});