This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Selim's profile picture

Secure sleep() and read() [Un-Solved]

Started by Selim, 11 March 2015 - 10:25 PM
Selim #1
Posted 11 March 2015 - 11:25 PM
So, I am making a program that I do not want ayone using being able to access the files. So, when I need to use os.pullEvent(), I use os.pullRawEvent() to stop someone from being able to Ctrl + T out of the program and wreak havoc. If I use sleep() or read(), as far as I know, they both use os.pullEvent(). How would I go about remaking sleep() and read() so that the programs that they are in cannot be terminated. Thanks!
Edited on 11 March 2015 - 10:27 PM
Quintuple Agent #2
Posted 11 March 2015 - 11:29 PM
If you have

os.pullEvent = os.pullEventRaw
near the start of your code, it will change os.pullEvent to os.pullEventRaw for all programs (until you change it back or restart the computer)
If you want to save the old pullEvent (which you should) do

local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
That way you can do

os.pullEvent = oldPull
to change it back.
HDeffo #3
Posted 11 March 2015 - 11:30 PM
I believe you are not quite understanding how pullEvent and pullEventRaw work. if you call os.pullEventRaw or not when events are passed they will still go to os.pullEvent to counter this we can actually redefine the function. pullEvent and pullEventRaw are exactly the same functions with the same handling except pullEvent handles terminate events specially.

As simply put as possible this will completely override os.pullEvent and terminate

os.pullEvent = os.pullEventRaw

EDIT: ninja'd
Edited on 11 March 2015 - 10:31 PM
Selim #4
Posted 11 March 2015 - 11:30 PM
If you have

os.pullEvent = os.pullEventRaw
near the start of your code, it will change os.pullEvent to os.pullEventRaw for all programs (until you change it back or restart the computer)
If you want to save the old pullEvent (which you should) do

local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
That way you can do

os.pullEvent = oldPull
to change it back.
That should work, thank you!
Edited on 11 March 2015 - 10:31 PM
InDieTasten #5
Posted 11 March 2015 - 11:30 PM
if you override the os.pullEvent function with os.pullEventRaw everything works as you are intending:
os.pullEvent = os.pullEventRaw
Thats it