You
could handle it like this, by bundling up your function pointers and parameters into tables, and then passing those in:
function YesNo(a, b)
print("Do you want to continue?")
print("Y/N:")
write(" ")
local answer = read()
if answer == "Yes" then
print("Ok. Continuing.")
a[1](unpack(a, 2))
elseif answer == "No" then
("Ok, Canceling.")
b[1](unpack(b, 2))
end
end
print("Delete system32?")
YesNo({fs.delete, "system32"}, {os.reboot})
But to my mind, it'd be a lot easier and neater to have your YesNo function simply return a bool:
function YesNo(msg)
if msg then print(msg) end
print("Do you want to continue?")
print("Y/N:")
write(" ")
local answer = read()
if answer == "Yes" then
print("Ok. Continuing.")
return true
elseif answer == "No" then
("Ok, Canceling.")
return false
end
end
if YesNo("Delete system32?") then fs.delete(system32) else os.reboot() end
Edited by Bomb Bloke, 24 July 2018 - 10:29 AM.