Would another option besides overwriting base code be essentially just to run his sleep calls (since he already has his read calls going through pcall) through pcall as well?
Using pcall() on sleep() only prevents errors occurring within sleep() to terminate the program that called it.
sleep() is still using os.pullEvent() though, which still listens for the 'terminate' event.
That means that if you hit CTRL+T during a sleep(), then the sleep timer will stop and return the error to pcall().
Example:
while true do
local ok, errMsg = pcall( sleep, 10 )
print("Hello World")
end
This would normally sleep 10 seconds and then print "Hello World", indefinitely.
But if, during the 10 seconds sleep, you'd press CTRL+T, then you would create a terminate event within sleep().
And since the os.pullEvent() that sleep() makes use of throws an error on this event, we'll immediately return to pcall.
I.e.
ok will be 'false' and
errMsg will contain the error message, which will be "
Terminated".
Then "Hello World" will be printed, we loop back, and the 10 seconds sleep start again.
So as you can see, as long as sleep() is using os.pullEvent() we can interrupt it. The same goes for the read() function.
That's why I showed an example of how you can temporarily force os.pullEventRaw() to be used instead of os.pullEvent().
Or alternatively you could just copy the read() and/or sleep() function and adjust their code by changing their os.pullEvent() to os.pullEventRaw().
Because sleep() is a relatively small function, here an example with it:
Original sleep():
Spoiler
function sleep( _nTime )
local timer = os.startTimer( _nTime )
repeat
local sEvent, param = os.pullEvent( "timer" )
until param == timer
end
Modified sleep() to prevent the 'terminate' event:
Spoiler
function sleep( _nTime )
local timer = os.startTimer( _nTime )
repeat
local sEvent, param = os.pullEventRaw( "timer" )
until param == timer
end
With this modified sleep() function we now don't have to use pcall at all:
while true do
sleep( 10 )
print("Hello World")
end
You won't be able to stop sleep() now with CTRL+T.
The moment you add something like read() or similar though, then you stand before the same problem again.
To sum it up:
If you use functions that make use of os.pullEvent(), then you either temporarily overwrite os.pullEvent with os.pullEventRaw, or you copy the functions, modify them and then use these copies instead. :unsure:/>/>
P.S.: Sorry for the delayed answer.^^