with all the plugins that are likely to show up soon, i thought someone had better address the subject of error checking, as 1 or 2 of you might produce something i can use, id rather it had proper plugin style error checking so i dont waist my time looking for errors in the wrong places
i ported the IRLUA_PLUGIN_* functions to lua to assist in error checking and to provide detailed description of the error, please use them in your scripts, this will save time for other users while debugging code.
the helper functions
example useCode:--######################################################################################################### -- IRLUA PLUGIN HELPER FUNCTIONS By MicroByte --######################################################################################################### --######################################################################################################### -- Sets a Global error message in the runtime engine. local IRLUA_PLUGIN_SetGlobalErrorMessage = function(nCode, sMessage) if _tblErrorMessages[nCode] then error("Error code "..nCode.." already in use, please use another.") else _tblErrorMessages[nCode]=sMessage end end --######################################################################################################### -- Checks the number of arguments in the table nd throws a syntax error If there are Not enough. -- This is useful For checking the number of arguments available To your aciton. local IRLUA_PLUGIN_CheckNumArgs = function(tbArgs,nArgs) local nCount=table.getn(tbArgs) if nCount < nArgs then error(nArgs.." Arguments expected, "..nCount.." Arguments passed.") end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a string. -- If Not, it tries To convert it To a string. If it can't it throws a syntax error. local IRLUA_PLUGIN_CheckString = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType == "string" then return tbArgs[nArg] else if tostring(tbArgs[nArg]) then return tbArgs[nArg] else error("Argument " .. nArg .. " must be a string.") end end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a string. -- If Not, it tries To convert it To a string. If it can't it throws a syntax error. local IRLUA_PLUGIN_CheckNumber = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType == "number" then return tbArgs[nArg] else if tonumber(tbArgs[nArg]) then return tbArgs[nArg] else error("Argument " .. nArg .. " must be a number.") end end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a boolean,. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckBoolean = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "boolean" then error("Argument " .. nArg .. " must be a boolean.") else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a function. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckFunction = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "function" then error("Argument " .. nArg .. " must be a function.") else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a thread. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckThread = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "thread" then error("Argument " .. nArg .. " must be a thread.") else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a userdata. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckUserData = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "userdata" then error("Argument " .. nArg .. " must be a userdata.") else return tbArgs[nArg] end end --######################################################################################################### -- END IRLUA PLUGIN HELPER FUNCTIONS --#########################################################################################################
Code:function MyFunction(...) -- this function requires 3 arguments, a string, a number and a callback function. -- check the number of arguments IRLUA_PLUGIN_CheckNumArgs(arg,3) local sString=IRLUA_PLUGIN_CheckString(arg,1) local nNumber=IRLUA_PLUGIN_CheckNumber(arg,2) local fFunction=IRLUA_PLUGIN_CheckFunction(arg,3) -- your function code below end
dont think its worth it ?, give it a try and you soon change your mind.

Reply With Quote

. There is only one variable type checking function now. It accepts three arguments, the third which is a table of allowed variable types.