pcall Bug/Issue
Posted: Tue Jul 31, 2012 2:56 pm
Hi everyone, I've got an issue using pcall in the following code:
The code is part of a command for my IRC-bot (This is why arg is hardcoded here, and say, is commented.)
When running this code, arg is executed in the main chunk, and thus crashing löve.
Running any 'correct' code works fine, I.E. "print('Hello world!')"
The issue is that pcall is being 'faulty' ; when correct code is ran, the ok and res variables are 'returned' by pcall however.
Does anybody know what I did wrong, and how I can correct my error?
Code: Select all
arg = "Non-code"
if arg then
ok, res = pcall(assert(loadstring(arg)))
if ok then
-- say(channel, "Code executed!")
else
-- say(channel, "Error occurred: " ..res)
end
end
When running this code, arg is executed in the main chunk, and thus crashing löve.
Running any 'correct' code works fine, I.E. "print('Hello world!')"
The issue is that pcall is being 'faulty' ; when correct code is ran, the ok and res variables are 'returned' by pcall however.
Does anybody know what I did wrong, and how I can correct my error?