389 posts
Posted 28 August 2015 - 05:19 AM
I'm creating a network system on a private server, I want to add the function os.getComputerIP() into bios.lua, which is easy enough. However, is there a way to prevent it being overriden?
8543 posts
Posted 28 August 2015 - 05:37 AM
No. You could use Dumb Metatable Tricks (TM) to prevent it being replaced in the table it resides in, but you cannot prevent things from replacing the os table with one of their own crafting, or any number of other ways to present a different function to a program.
The better question is, why would you even try to prevent it from being overriden?
389 posts
Posted 28 August 2015 - 05:53 AM
I thought that'd be the case unforunately, I basically want a unique way to identify a computer besides their ID that cannot be altered/overriden like an ID.
Edit: "Dumb Metatable Tricks ™" ~ Lyqyd 2015
Edited on 28 August 2015 - 03:54 AM
797 posts
Posted 28 August 2015 - 12:06 PM
Well, then again, an environment is simply a table and is "metatable-able" so you could prevent os from being overridden. Anything with control over the environment of a function that will be called will be able to get around even this though.
However… there is a way of checking the validity of a function by making it a table with an __tostring and __call metamethod. That way, tostring( os.getComputerIP ) could return "networkipgetter" and be called just the same as a normal function. This is certainly possible to get around, but the average computercraft user would be amazed it doesn't return "function: 0fab178e" and not have a clue how to replicate it I'd say.