The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Remove Empty Strings From The End Of A List In Lua

TODO: Pull subtitle into page object
Code
local function remove_trailing_empty_lines(source)
  local reversed = {}
  local load_counter = #source
  local hit_content = false
  while load_counter > 0 do
    if source[load_counter] ~= "" then
      hit_content = true
      table.insert(reversed, source[load_counter])
    elseif hit_content == true then
      table.insert(reversed, source[load_counter])
    end
    load_counter = load_counter -1
  end
  local trimmed = {}
  local reverse_counter = #reversed
  while reverse_counter > 0 do
    table.insert(trimmed, reversed[reverse_counter])
    reverse_counter = reverse_counter - 1
  end
  return trimmed 
end

local source = { "a", "b", "c", "" }
local updated = remove_trailing_empty_lines(source)

print(#updated)
print(updated[1])
print(updated[2])
print(updated[3])




Results
3
a
b
c

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Remove Empty Strings From The End Of A List In Lua

I needed to remove empty strings from the 
end of a table. This is what I ended up with:

-- code
-- lua

local function remove_trailing_empty_lines(source)
  local reversed = {}
  local load_counter = #source
  local hit_content = false
  while load_counter > 0 do
    if source[load_counter] ~= "" then
      hit_content = true
      table.insert(reversed, source[load_counter])
    elseif hit_content == true then
      table.insert(reversed, source[load_counter])
    end
    load_counter = load_counter -1
  end
  local trimmed = {}
  local reverse_counter = #reversed
  while reverse_counter > 0 do
    table.insert(trimmed, reversed[reverse_counter])
    reverse_counter = reverse_counter - 1
  end
  return trimmed 
end

local source = { "a", "b", "c", "" }
local updated = remove_trailing_empty_lines(source)

print(#updated)
print(updated[1])
print(updated[2])
print(updated[3])






-- results/

3
a
b
c

-- /results


-- categories
-- Lua 

-- metadata
-- date: 2023-10-25 14:50:48
-- id: 2xget6vp
-- site: aws
-- type: post
-- status: published