0

I'm new to stackoverflow and I'd like to ask a question regarding the use of dofile()/dostring() in lua. Basically, what I'd like to do is run a piece of code using either dofile() or dostring(), which is created at runtime. However, it is possible for variables or classes to overlap with the "normal" source code/rest of the program. Thus it could happen that the code generated at runtime alters and manipulates the values of variables it shouldn't touch. Since the generated code depends on the user, I have no control over this and can't necessarily prevent it. Is there a way to run code at runtime in lua, but independently from the rest of the program?

Andronicus
  • 25,419
  • 17
  • 47
  • 88
  • What kind of communication is needed between user's code and the rest of the app? There's various approaches - running untrusted code in a sandbox within app's VM, or running that code within separate VM dedicated to user code. The complexity and amount of data movement will vary depending on the task and goals. – Vlad Dec 28 '19 at 17:50
  • You need a [sandbox](https://stackoverflow.com/q/1224708/1847592) – Egor Skriptunoff Dec 28 '19 at 18:06
  • Thanks for your answers! Basically, my app allows users to create games and program its objects. When hitting play, the app generates the code as if it were a standalone project, checks it for syntax errors and then runs it. The only communication between both VMs needed, would be a way to exit the game and return back to the editor. I should add, however, that I am using Codea as my IDE, which is an iPad app. Could you still use a VM for that? – Elias__M Dec 28 '19 at 21:06

0 Answers0