From a37a28d1b705a3ddee1878dc6406fb27b8eafea8 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 17:34:00 +0000 Subject: Store boards not just as strings, but as tables with the topic as a member. --- telem.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/telem.lua b/telem.lua index 9612a4b..bef5569 100755 --- a/telem.lua +++ b/telem.lua @@ -56,13 +56,17 @@ end -- Internals function update_boards() - for board in lfs.dir(path.join(_BBS_ROOT, "boards")) do - if string.sub(board, 1, 1) ~= "." and not board_names[board] then - board_names[board] = true + for boarddir in lfs.dir(path.join(_BBS_ROOT, "boards")) do + if string.sub(boarddir, 1, 1) ~= "." and not board_names[boarddir] then + local board = {} + board.name = boarddir + board.directory = path.join(_BBS_ROOT, "boards", boarddir) + board.topic = file.read(path.join(board.directory, "topic")) + board_names[board.name] = true table.insert(boards, board) end end - table.sort(boards) + table.sort(boards, function(x,y) return x.name > y.name end) end function check_at_board() @@ -147,9 +151,7 @@ function do_board() local topic_file = path.join(board_dir, "topic") file.write(topic_file, desc) -- Update representation of BBS - board_names[board] = true - table.insert(boards, board) - table.sort(boards) + update_boards() -- Done! print("Board created.") end -- cgit v1.2.3