-- ********************************************************************** -- * Errors -- * -- * version 0.1 -- * -- * (c) 2005 Hi-Project Ltd. -- ********************************************************************** module "LUNAERROR" local LASTERROR = "" local LASTERRORN = "" local LASTERRORC = 0 -- ERROR CODES local ERROR_CODES = { ERROR = 9999 } -- ERROR MESSAGES local ERROR_MESSAGES = { ERROR = "ERROR" } function seterror(errcode) LASTERRORC = errcode LASTERRORN = "" local idx = table.foreach(ERROR_CODES,_chkcode) if idx == nil then LASTERROR = "" else LASTERRORN = ERROR_MESSAGES[idx] LASTERROR = "ERROR #"..LASTERRORC..", "..LASTERRORN end return LASTERROR end function seterrorbyname(errname) LASTERRORC = 0 LASTERRORN = "" if errname == nil then LASTERROR = "" else LASTERRORC = ERROR_CODES[errname] LASTERRORN = ERROR_MESSAGES[errname] LASTERROR = "ERROR #"..LASTERRORC..", "..LASTERRORN end end function geterrorcode() return LASTERRORC end function geterrormessage() return LASTERROR end function clearerror() LASTERRORC = 0 LASTERRORN = "" LASTERROR = "" end function adderror(errcode, errnumber, errmessage, errlanguage) -- error language not used yet ERROR_CODES[errcode] = errnumber ERROR_MESSAGES[errcode] = errmessage end -- INTERNAL function _chkcode(...) local key = arg[1] local value = arg[2] if value == LASTERRORC then return key else return nil end end