Posted 06 January 2016 - 04:21 PM
I designed this framework to ensure that the programs that ran on the computer had the required peripherals to successfully run without any problems. The idea behind this api is that you supply it with a table of features for the api to check to see if the computer running the program has peripherals/features to successfully run it. The api also allows you to add custom feature checks incase you need to anything else custom, but it should be able to fallback on the
code:
http://pastebin.com/Emb2Etrg
api:
Features that can be checked for are the following:
sample code:
code:
http://pastebin.com/Emb2Etrg
api:
Supports.features(requiredFeatures)
Description:
When supplied with a list of required features it will check to see if the computer has them.
Parameters:
requiredFeatures - A table consisting of strings of the features required.
Returns:
true - All features supplied are found running on the computer.
false - Some features were not found on the computer.
Supports.displayMissingRequirements(missingRequiredFeatures)
Description:
When supplied whith a list of missing required features, It will display them in a decently formmated message.
Parameters:
missingRequiredFeatures - A table consisting of all the required features.
Returns:
Nothing.
Supports.registerCheckedFeatured(checkedFeatureName, checkedFeatureFunc)
Description:
When supplied with a name of a feature and a function to check the feature state it will validate that that feature is properly setup for the computer.
Parameters:
checkedFeatureName - The name of the feature to register.
checkedFeatureFunc - A function which returns true or false depending on the features requirements.
Returns:
true - The feature was successfully registered.
false - The feature failed to be registered.
Supports.unregisterCheckedFeature(checkedFeatureName)
Description:
When supplied with a name of a existing feature being used for validation, It will remove it validation.
Parameters:
checkedFeatureName - The name of the feature to remove.
Returns
true - The feature was successfully unregistered.
false - The feature failed to be unregistered.
Features that can be checked for are the following:
- turtle
- melee
- mining
- digging
- felling
- farming
- crafty
- wireless
- wired
- advanced
- monitor
- modem
- printer
- drive
sample code:
os.loadAPI("Supports")
local foundRequiredFeatures, missingRequiredFeatures = Supports.features({"advanced", "turtle", "wireless"})
if not foundRequiredFeatures then
Supports.displayMissingRequirements(missingRequiredFeatures)
return false
end
print("This program has all the requirements to run.")
Edited on 06 January 2016 - 11:11 PM