lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I would do something like that, although there might be a better way (look-up takes some memory for a faster access):

local GUIERRORBASE = 5000
local GUI_ERRORS =
{
  'BRSTK_VALIDATION_FAILURE',
  'BRSTK_SCAN_NOT_FOUND',
  'BRSTK_FIELD_NOT_FOUND',
  'BRSTK_LABEL_NOT_FOUND',
  'BRSTK_INVALID_SERVICE_XML',
  'BRSTK_INVALID_CATALOG_XML',
  'BRSTK_VALIDATOR_LOAD_FAILURE',
  'BRSTK_SERVICE_NOT_INITED',
  'BRSTK_MEMORY_ALLOC_ERROR',
  'BRSTK_VALIDATOR_NOT_FOUND',
  'BRSTK_END_OF_FILE',
}
print(GUI_ERRORS[2])
local GUI_ERRORS_LOOKUP = {}
for i, v in ipairs(GUI_ERRORS) do
  GUI_ERRORS_LOOKUP[v] = i
end
function GetGUIErrorNumber(errorName)
  if errorName == 'BRSTK_VALIDATION_SUCCESS' then
    return 0
  end
  local index = GUI_ERRORS_LOOKUP[errorName]
  if index == nil then return -1 end
  return GUIERRORBASE + index + 1000
end
function GetGUIErrorName(errorCode)
  local name = GUI_ERRORS[errorCode - 1000 - GUIERRORBASE]
  if name == nil then return '' end
  return name
end
print(GetGUIErrorNumber('BRSTK_INVALID_SERVICE_XML'));
print(GetGUIErrorName(6005) );



--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --