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

Code engine (Context) #4

Open
TechStudent10 opened this issue Dec 18, 2022 · 2 comments
Open

Code engine (Context) #4

TechStudent10 opened this issue Dec 18, 2022 · 2 comments
Assignees
Labels
backend Issues relating to the backend

Comments

@TechStudent10
Copy link
Member

TechStudent10 commented Dec 18, 2022

The Context Engine must be completed in order for scripting to work.

The way the Context Engine is supposed to work is that it will

  • Get the main.js script
  • Limit its accessibility to scope

The app also needs a Context class that will help the user

  • Add intractability to their applications
  • Get information about elements (see Elements #5)
  • Send/receive information from another server
@TechStudent10 TechStudent10 self-assigned this Dec 18, 2022
@TechStudent10 TechStudent10 added the backend Issues relating to the backend label Dec 18, 2022
@TechStudent10 TechStudent10 mentioned this issue Dec 24, 2022
@TechStudent10
Copy link
Member Author

For future reference:

Node.JS has a built-in vm module that allows you execute JavaScript in a sandboxed or contextified environment: https://nodejs.org/api/vm.html#vm-executing-javascript

Example (from the Node.JS docs):

const vm = require('node:vm');

const x = 1;

const context = { x: 2 };
vm.createContext(context); // Contextify the object.

const code = 'x += 40; var y = 17;';
// `x` and `y` are global variables in the context.
// Initially, x has the value 2 because that is the value of context.x.
vm.runInContext(code, context);

console.log(context.x); // 42
console.log(context.y); // 17

console.log(x); // 1; y is not defined.

@TechStudent10
Copy link
Member Author

Or better yet, using Lua: https://npmjs.com/package/wasmoon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Issues relating to the backend
Projects
None yet
Development

No branches or pull requests

1 participant