luaexecutionopencomputers

how to execute a string as a line of code in lua


I made myself a drone os in the minecraft mod Opencomputers, but I want to be able to make it run any line of code once recieved from the network card. I've tried everything I found here but none of it works, or atleast I haven't done it the right way. Can someone give me an example of something that will run a string as code?

This is one of the things I've tried (message is a string)

os.execute(message)

Is there a way to convert the string to just, not a string so I can at least see if os.execute will work how i want it to?


Solution

  • https://www.lua.org/manual/5.1/manual.html#pdf-loadstring

    To load and run a given string, use the idiom

     assert(loadstring(s))()