Lets say I want to ban an object's method from being used. This requires me to know what method needs to be banned, hence the question.
This isn't a roblox Default object, like Part, but rather a theoretical object held together by a table.
In order to ban a method from it, I'm going to give the object a ban method that takes in the argument of a method and adds it to the ban list. That way it only needs to glimpse at the ban list to see if the method is within it to determine what function can run.
local Object = {} function Object.new(someName) name = someName; bannedList = {} temp = {} function temp:Print() if checkValidity(temp:Print()) then --This won't work, will cause a stack overflow. print(name); end end function temp:Ban(someMethod) table.insert(bannedList, someMethod = true) --not quite sure if this is the right dictionary-key reference here end function checkValidity(someMethod) if bannedList[someMethod] ~= nil --if it's there return false --invalid else return true -- valid end end return temp; end return Object --Driver test1 = Object.new("Bob"); test1:Print(); test1:Ban(test1:Print()); -- Again, will not work test1:Print(); --Should do nothing
As you can see, I'm trying to make it that some Instance can tell Object not to use its methods. Though I don't know how to refer to them (Is it something like Object:Ban?)
How do I do this reference? Kudos to whoever could make a more efficient method to ban a function as well
A method is just a member function which is invoked with the first argument implicitly as the container. Your system is actually a little flawed as it's not being properly applied, but nonetheless I will show you how it can do it.
function temp:Print() if checkValidity(temp.Print) then print(name); end end function temp:Ban(someMethod) bannedList[someMethod] = true; end
At this point, you should notice that your ban function now requires a function and not a name. This is your fault, and I blame you. I'm not going to fix it, because I'm lazy and it's not my problem.
I hope I helped