Search code examples
luaopencomputers

Is there to way to run code from a variable in Lua


So, I've got this very interesting position where I have an entire set of code loaded into a variable, and I desperately want to run this code as it defines critical variables and functions for later in the code. Is there a way for me to do so? I haven't tried anything because, frankly, I have no idea what I have to do in this situation.

Main program:(Code is after the variable is loaded.)

while true do
trick.setscr(1,2,"Success!")
end

Variable loaded code

--Graphics 1.0
local card = component.proxy(component.list("gpu")())
_G.video[80]
table.insert(system, 0)
function trick.print(y, str)
card.fill(x, y, 1, y, str)

end
function trick.setscr(x,y,str)
card.fill(x, y, x, y, str)
end
function trick.clear()
card.fill(1, 1, 50, 16, " ")
system[6] = 0
end

Solution

  • Yeah I was dumb. All I had to do was implement a function that used the load command, like this.

    run = load(system[4])
    run()
    

    This adds the functions without issue.