sCCripts/jlib/input.lua

29 lines
632 B
Lua

-- Created by Jef Roosens
--
-- Useful functions for receiving input from the user
local module = {}
module.logger = require("jlib.log").Logger:new{level = -1}
-- Read an integer
--
-- @param prompt prompt string to show
-- @param negative wether or not the number can be negative; defaults to false
function module.read_int(prompt, negative)
while true do
write(prompt)
local num = tonumber(read())
if num and num >= 0 or not negative then
module.logger:info("Input: " .. num)
return num
end
print("Please enter a valid number.")
end
end
return module