2

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
Missingno50
  • 83
  • 10
  • 1
    https://www.lua.org/manual/5.3/manual.html#pdf-load – Piglet Apr 23 '20 at 07:25
  • I haven't checked yet but I'm pretty sure that one is just going to make me look absolutely stupid. I overlooked the load command earlier because I didn't think it'd help based on syntax alone but I'm going to examine that more closely now. – Missingno50 Apr 23 '20 at 07:34
  • @Piglet So I decided to add the line `load(system[4])` right before the while true do to try to get it to run the defining of the functions but it didn't help(same old error but this time a line down). Something tells me I'm on the right track thanks to you, but I am not sure what I'm missing. – Missingno50 Apr 23 '20 at 07:39
  • @Missingno50 - `same old error but this time a line down` What is the error message? – Egor Skriptunoff Apr 23 '20 at 08:39
  • Might as well tell you, but basically it was just spitting out "attempt to call for field 'setscr' (a nil value)". Absolutely unhelpful. – Missingno50 Apr 23 '20 at 08:58
  • this error message is very helpful as it exactly tells you what you're doing wrong. you're trying to call a nil value. why that value is nil, Lua cannot know. That's your job to find out. – Piglet Apr 23 '20 at 09:17

1 Answers1

0

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.

Missingno50
  • 83
  • 10
  • 1
    that's why they write in the manual "If there are no syntactic errors, returns the compiled chunk as a function" and that function of course has to be called to have any effect – Piglet Apr 23 '20 at 09:16