I want to make private function for my language interpreter .
problem is with that i have some variables and functions i want not to be executed by the user
for example
function run1(){
alert("1")
}
var name=0;
let exported= privaterun( ["run1()"] , function(){
export=20
console.log(name) // undefined
run1() // run1 is not defined
},["export"] )
alert(exported.export);
this is a example what i want to implement this doesn’t needs to look like this but i want have that behavior
yeah i know it could be done by making javascript interpreter in javascript but that nonsense for me for example make for loop and to every variable and function name add _1
it will still be possible to skip it somehow by the user .
and and will not be able to use variables with _1
i need a function or example to do that i use
let system;
function sandbox_wrapper(
system2, gl, c5tx, ox, oy, mouseX, mouseY, screenX, screenY,screenW, screenH, mouseAction, state, win) { const system = { system2, gl, c5tx, ox, oy,
mouseX, mouseY, screenX, screenY,
screenW, screenH, mouseAction, state, win};
function runner(code) {
try {const sandboxedFn = new Function("sys", `with (sys) {${code}}`); sandboxedFn(system);} catch (e) {}
}
return {run: runner, }
}
system = sandbox_wrapper( 1, this.gl, c5tx, this.x, this.y, this.mouseX, this.mouseY, this.x,this.y ,this.w,this.h , this.mouseAction, this.state ,this);
system.run(parsedcode);
but this doesn’t prevent for executing global functions and editing global variables .
is there way to do that ??
i would