LuaJIT has table.clear()

Ever wanted to empty a table without going though a loop or creating a new table and bothering the garbage collector?

Just table.clear(that_table)!

If you're writing a library and you're being nice to non-jit lua users, then you can just take a bit of extra time to check if it exists.

if table.clear then
  -- deal with it another way

Rendering a transparent background with LOVE2D and OBS

First of all, thank you @xkeeper for this, who found this worked even after being told "It can't be done".

function love.draw()
    -- This is all you need to do in your Love2D Code, set the background to transparent.
    -- Note, this will still appear as black in the Love2D Game Window.,0,0,0)
    -- Draw things after here!

Setting up the OBS Capture

  1. Game Capture
  2. Mode: Capture Window
  3. Allow Transparency: True/Checked

That's It?

That's it. As long as you don't change the background, anything drawn in the love2D window will be drawn as if on top of a transparent background. Great for fun effects without having to use a chroma key.

Sorting a Lua Table Alphabetically

Note: Lua will sort tables in place and will replace the original table.

The really cool thing about programming is that when it comes down to it, everything is a number. So, if we need to sort a (number-indexed) table, we can use the character number to do a nice alphabet sort of everything in it. We will not be talking about extended characters or Unicode today.

local cool_things = {eggbug, dog, Rain}

    local function customsort_alphabetical(a, b)
      return string.lower(a) < string.lower(b)
    -- Capital letters have a lower character number, 
    -- so if we did not make everything check as lowercase, 
    -- Rain would sort to the top of the list.
    table.sort(cool_things, customsort_alphabetical)
    -- The table is now sorted as: cool_things = {dog, eggbug, Rain}

So, the table.sort function will work through our list. While working it picks up two things in our list and then makes them both lowercase. While holding eggbug and the now lowercase rain, it takes the first character of each, looks at the value of that character and then sorts it in the table. Since the value of e is less than r, eggbug sorts before rain.

Note: Read more on the Programming in Lua website.



Version 2.0, released May 1, 2024.