Posted 01 February 2014 - 08:05 AM
so lets say you have a program that adds virtual folders. clear right, you just make local copies of all the computercraft file programs and modify them to where they are able to interact over the network. easy, dont. but what if you had 3 programs making local copies of the file programs, only the last written version would survive. here is where hooks come in handy. hooks can be made in many diffrent ways, ill show you 2 way, the first one uses api's and the function name would be used as the hook name. for example
the avantage of the second system is that all the hooks registered with the same hook name will be executed by the system in a particular order. hooks could also be used for permission checks where for example the hook "canUserRunProgram" will be ran to check if a user can run that specific program that is specified in the arguments. also when a hook returns anything it will not run any other functions under that hook type, if nothing is returned the next hook will be executed ect…
so to make it all clear
just a little idea to make CC more advanced and personalized because now we have to hack our way around, wich is fine by me, but some prefer to use the legitemate route. :)/>
-wilco
virtualfolders.onFolderCreate = function(sPath) return true end
also a way could be through a hook register system like so:
hook.add("onFolderCreate","myhook",function(sPath) return true end)
hook.run("onFolderCreate","mynewfolder") -- this would return true like above
the avantage of the second system is that all the hooks registered with the same hook name will be executed by the system in a particular order. hooks could also be used for permission checks where for example the hook "canUserRunProgram" will be ran to check if a user can run that specific program that is specified in the arguments. also when a hook returns anything it will not run any other functions under that hook type, if nothing is returned the next hook will be executed ect…
so to make it all clear
hook.add("canUserRunFile", "myhook", function(sPath, sName, tArgs) return true end)
teh shell program would run this
hook.run("canUserRunFile", "rom/programs/computer/rednet/mail", "mail", { "host", "hostname" })
this would run through the hooks until a value is returen, in this case true or false. if nothing is return in teh first hook it will move on to the second, so by using this system you gotta make sure you return true ot nothing,just a little idea to make CC more advanced and personalized because now we have to hack our way around, wich is fine by me, but some prefer to use the legitemate route. :)/>
-wilco