New to lua and Mushclient so if this is simple my apologies I've searched quite a bit
I would like to create a lua function that interacts with the mud but behaves like a standard function, i.e. returns data.
The example I have chosen is to gather all area info from the screen after a command and return it as a parsed table.
Thanks in advance.
I would like to create a lua function that interacts with the mud but behaves like a standard function, i.e. returns data.
The example I have chosen is to gather all area info from the screen after a command and return it as a parsed table.
function capture_area_info()
local max_captures = 500
local captures = 0
local areas = {}
local area_line_regex = rex.new([[\s+(?P<min_level>\d+)\s+(?P<max_level>\d+)\s+(?:(?P<level_lock>\d+)\s+)?(?P<area_id>\w+)\s+(?P<area_name>[A-za-z0-9 ',-]+\w)\s*$]])
Send("areas keywords")
wait.make( --coroutine
function()
while captures < max_captures do
captures = captures + 1
local line = wait.match('*', 10)
local a, b, matches = area_line_regex:match(line)
if matches then
areas[#areas+1] = {area_id=matches['area_id'], area_name=matches['area_name'], min_level=matches['min_level'], max_level=matches['max_level'], level_lock=matches['level_lock']}
print(#areas)
end
if string.match(line, [[^'Lock' means you cannot enter until you are that level or higher.$]]) then
done = true
break
end
end
end
)
-- I would like this to return the gathered area info but because wait is a coroutine this returns nil immediately.
return areas
end
Thanks in advance.