So, remember that time when you were playing on a server and a rule breaker comes and opens up your computer terminal, then types 'shutdown' on your computer when it was doing a important task in multishell? Well this is for you.
Overriding Functions are actually pretty easy.
You can do them in API's where they put there functions in 'non-local' tables.
You can override hello, and foobar here:
test = {
hello = function() print("Hello World!") end,
foobar = function() print("Foo Bar!") end,
}
But you cant here:
local test = {
hello = function() print("Hello World!") end,
foobar = function() print("Foo Bar!") end,
}
Why? Local is a attribute that will only make that object available to that program/API.
Without it, anything can access it.
Also, if the function is out of a table, you can still access and override it.
Lets say i made a file named test.
function hello()
print("Hello World!")
end
function foobar()
print("Foo Bar!")
end
The functions hello and foobar will go under a table named after the file name.They will still work the same and anyone can access it.
So, you know the basics of functions in tables.
Now lets get to overriding.
So, lets say im creating a file called: "noshutdown".
I want it to say "No." when os.shutdown() is called.
To do that,
function os.shutdown()
print("No.")
end
Run the program, and when os.shutdown() is called, it would print "No." instead of shutting the computer off.You can do this for all functions that arent local.
Basically your altering functions until you restart. (unless you have it saved as startup ;)/> )
It is kinda like Open Terminal's OTOS.Hook().
So, like above you can do it for every function that isnt local, meaning people that really want to be a big @!&#% can do this:
function shell.run(...)
printError("No such program")
end
function os.run(...)
return nil
end
Mean eh?