Thalassicus
Bytes and Nibblers
I'm having difficulty finding the proper keywords/syntax to create and use enumerations in Lua. In particular, how do I do these two things:
- Make LevelType immutable.
- Make :setOutputLevel and
rint require a LevelType for the first parameter.
PHP:
LevelType = {
DEBUG,
INFO,
WARN,
ERROR
}
LoggerType = { logLevel = DEBUG };
function LoggerType:new(o)
o = o or {};
setmetatable(o, self);
self.__index = self;
return o;
end
function LoggerType:setOutputLevel(level)
self.logLevel = level;
end
function LoggerType:print(level, text)
if level >= self.logLevel then
print(text);
end
end
-- usage example
-- myLogger = LoggerType:new();
-- myLogger:setOutputLevel(DEBUG);
-- myLogger:print(ERROR,"Error message");