
I have an idea. No wait. I lost it. Wait. There it is, again.
The mighty binary digit. (Shortened to “bit”). Physically, it is the state of a tiny switch. It’s the corner stone to tricking rocks to think for us.
On it’s own, it doesn’t mean anything. However, we can use them to express different types of data. You can join them to represent anything from a single character to literally all of the internet.
When you do this, you create a data type as in “What type of data should these bits represent?” We’re going to build, in binary, some of the core data types in Lua.

If you wish to make an apple pie from scratch, you must first invent the universe. – Carl Sagan, 1980
It might feel like I’m going full Carl Sagan on you, but having knowledge that these concepts exist will help you when you’re developing in the future. I promise.
Every coding language has it’s own data types.
Sometimes they’re obvious like in C where you declare something as an int (integer).
Sometimes they’re a little more hidden like in Lua when you just say x = 10
(that 10 is an integer just like in C)
This article is going to cover Lua specific data types to help you understand the Playdate SDK (Software Development Kit). We’ll explore how these data types are built from their underlying structure, and some of the quirks of Lua for those who have some previous coding experience.
If you’re here just to learn some information about Lua, jump to the TL;DR at the bottom.
Boolean
When you look at a single bit alone, we can start to look at our smallest data type, the boolean. A single bit is all you need for a boolean. They can be either true or false. It doesn’t seem like much at first, but the boolean is incredibly powerful. Let’s look at my favorite boolean value in real life (it involves candy).

I hope they have full sized butterfingers – Dracula, probably
The boolean in this case is the porch light. What information can you get from just this porch light being on?
- The person who lives here is home.
- The person who lives here celebrates Halloween.
- They still have candy to give away.
In code, it could look something like this:
if date == "October 31" and porch_light == true then
trick_or_treat()
end
Today isn’t going to cover coding, but there are 5 sneaky boolean values in the code above.
- porch_light is a boolean. It’s either true or false.
- true is a boolean.
- date == “October 31” resolves to a boolean. The statement is true or false.
- porch_light == true resolves to a boolean. The statement is true or false.
In Lua, the Boolean type has 2 states denoted by true or false.
Challenge!
Comment if you find the 5th boolean!
Special Note on Lua
In Lua, boolean values are treated a little different than most other languages. If you’re coming from a coding background and are here to learn Lua, using comparative operators gets a little weird. When comparing values, they need to be of the same type, and boolean values are explicitly the value “true” or “false”
> print(0 == false)
false
> print(0 == true)
false
“Is the number 0 equal to the boolean false? No”
”Is the number 0 equal to the boolean true? Also no.”
Number
In Lua, there are two sub-types of number. They’re either integers, or floats.
- Integers are whole numbers.
- Floats are any number with a decimal point in it.
That’s all you REALLY need to know. But if you’d like to dive a little further and invent integers, read ahead! If not, skip down to Strings.
Integers
Let’s invent how to build an integer from scratch, so we can appreciate what Lua (and other coding languages) is doing for us under the hood. We have the power of the boolean at our disposal, how could we use that to count?
Imagine, for a moment, you live in a world with a currency shortage, and you will go to jail if you own two of the same coin.
- You mow your neighbor’s lawn, and she gives you a single coin.
- You have one $1 coin.
- That’s not enough to buy a Playdate. Let’s mow some more lawns.
- You mow another lawn, and you get another $1 coin.
- Uh-oh. You’re about to go to jail, so you go to the bank.
- You give them your two $1 coins, and they give you one $2 coin.
- You still don’t have enough for a Playdate. You mow another lawn.
- You get a new $1 coin. That’s OK!
- You own one $2 coin, and one $1 coin. Total Money: $3
- You mow another lawn. You get another $1 coin.
- Uh-oh. You have two $1 coins again.
- Let’s make another trip to the bank.
- You give your two $1 coins in and get a second $2 coin.
- Uh-oh. You have two $2 coins.
- You trade those in for a $4 coin.

I need to mow 11000111 lawns! – You
Congratulations! You now understand how to convert Base 10 counting into a Base 2 binary system.
Each bit is assigned a number, and if it’s “on / true”, it adds that up to the total.
001 = 0 + 0 + 1 = 1
010 = 0 + 2 + 0 = 2
011 = 0 + 2 + 1 = 3
100 = 4 + 0 + 0 = 4
Now, if we were to combine 8 bits into a byte, how high can you count with 8 binary digits? In other words, what is 11111111?
Know the answer? Want help? Leave a comment!
Still struggling with base 2? Imagine having to count in base 60, then base 60 again, then base 24, then base 7, then base 30 (except sometimes it’s base 31, or 29, or 28) Oh, and also base 12. And base 365. You already do this every day. Seconds, Minutes, Hours, Days, Weeks, Months, Years. If you can do that, you can do anything.
Floats
Representing floating point numbers is a little more complicated to represent with human readable binary. If you want to deep dive into it, let me know in the comments and I’ll do a follow up article.
For a beginner, just know that floats are any number with a decimal point.
3.14, 1.618, or 2.0 are all floats.
Challenge!
You know how to count in base 2 now, how would you count in base 16?
Special Note on Numbers for Playdate
Numbers are signed 32-bit in Playdate.
The integer range is [-2,147,483,648 to 2,147,483,647]
If you go outside this value, you will get overflow.
String
So far we’ve turned binary into boolean values. Boolean values into numbers. What if we take numbers, and turn them into characters?
Let’s invent the character and assign them to numbers! It might make sense to start at 1 with familiar letters, and if you were going to recreate characters today, you might. But let’s look at how they’re actually implemented.
The alphabet starts at 65
A = 65 = 01000001
B = 66 = 01000010
…
Z = 90 = 01011010
Understanding this won’t be terribly useful for Playdate since there’s no keyboard. But if you end up journeying into the WASD territory for making games, these codes can be quite helpful.
So, what is a string?
Now that we have characters, we can combine them into words! It’s just a collection of characters. We define them in Lua by putting them in “double”, or ‘single’ quotes.
Challenge!
Use what you know about binary, and this ascii chart to decide the strings below:
Easy Mode – Numbers → Characters → String
110 111 119 32 116 97 99 107 108 101 32 104 97 114 100 32 109 111 100 101
Hard Mode – Binary → Numbers → Characters → String
01000001 01100011 01101000 01101001 01100101 01110110 01100101
01101101 01100101 01101110 01110100 00100000 01010101 01101110
01101100 01101111 01100011 01101011 01100101 01100100 00100001
Special Note
It’s important to know that the number 123, is not the same as the string “123”.
123 in binary is 01111011
”123” in binary is 0110001 0110010 0110011
123 does not equal “123”
Intermission

Rest and Reflect
Wow, that was a lot. Take a seat by the fire for a moment.
You’ve gone from a bit → boolean → numbers → characters → strings.
You don’t need to carry this in your pack for the rest of your journey. Leave it in the chest at camp, and just know it’s there if you ever need it for the final boss.
We’re done looking at binary. We’re done building the core data types. Translating into binary no longer makes sense from a human perspective. Trust the tiny magic rocks in your computer to do the work. The last section of this article is just a little taste of the final base data types in Lua, and then you can be on your way to greater things.
UserData
UserData is a complex one. It’s how Lua and the C language interact. Sometimes Lua isn’t fast enough to do the work we need it to do. You can write C code to do the heavy lifting.
This is an advanced topic, but just understand it’s raw binary data that needs to be encoded, and/or decoded.
Function
A function is a block of code that is designed to complete a task. The way to define the rules of what a function should and shouldn’t do is up for debate, and has entire books written about it.
For the sake of the beginner, a function makes it so you can do something again and again without copy and pasting code.
function square(x)
return x * x
end
y = square(10)
print(y)
> 100
function bark()
return print("WOOF!")
end
bark()
> WOOF!
Here we have two functions.
- The square function will return a number times itself.
- The bark function will print WOOF! to the screen
Challenge!
Play a game, or use a program on your computer.
What are some functions you think are happening under the hood?
Special Note on Functions for Lua
Functions are treated like “first class” citizens. That means you can put functions into variables, you can return functions, you can treat them like any other data. That might not mean a lot to beginners, but as you get the hang of things, it’s a super powerful tool at your disposal.
Table
Tables are the beauty of Lua. Not only are they an extremely powerful data type, they are also the only data structure in Lua.
We can use tables to be our very own custom data types. We can use tables to hold a bunch of similar values (like maybe all the names of your pets?).
ALL Tables are a collection of “key:value” pairs.
character = {
name = "Boulder Mage",
health = 3,
has_hat = true,
has_staff = false,
}
print(character.name)
> Boulder Mage
print(character["name"]
> Boulder mage
This table has 4 entries, a string, a number, and two boolean values. If you create a table with keys, you access those values by table.key or table[“key”]. If you create a table without keys, things become a little different.
my_cats = {
"John Wick",
"Hugo",
"Big Fat Freddy",
}
print(my_cats[3])
> Big Fat Freddy
In the example above, we create a table with no keys. We access the values by order, in a bracket[ ].
Challenge
Try to make a table that would be the data needed for a square.
I bet you could think of a few different ways!
Special Note on Tables for Lua

I can’t know how to hear anymore about tables!
Tables are NOT arrays. Tables are tables. When you don’t give a key for the table, it assigns keys in order from 1, 2, 3 and so on. They do not start at 0. There is no pointer arithmetic because it’s not an array. The data is not guaranteed to be contiguous. Don’t fret if this doesn’t make sense, yet. I will be doing a whole article just on tables.
Nil
Nil is something you probably haven’t come across before even if you’ve coded in other languages. It’s very specifically it’s own data type.
It’s almost, but not quite, entirely unlike zero.
- It is NOT zero.
- It is NOT false.
- It is NOT an empty string.
- It is NOT an empty table.
- It is NOT a function.
- It is NOT anything.
- It IS nothing.
It is used to represent the absence of a value. You might use nil to check if a variable exists, or if a table contains a certain key. You also can set a variable to nil to remove it from memory.
Special Note on Nil for Playdate
If you set something to nil, the garbage collector will start to remove it from memory. Might happen right away, might not. Much like in real life, you can’t control the garbage collector. They march to the beat of their own drum. Setting things to nil can affect performance and cause games to lag because it’s cleaning up the mess.
Premature optimization is the root of all evil — Donald Knuth.
Don’t worry about it, just know it is there and that it might be a cause of your lag spikes and then you can worry about optimizing.
Thanks for reading, be in touch!
If you need clarification on anything, please comment! I’m happy to help.

I wonder what would happen if rocks really could think on their own…
TL;DR: Data Types
- Boolean
- Can be “true” or “false”
- You cannot compare other data types to boolean values.
- 0 does not equal false
- Numbers
- There’s one data type for Float and Integers. Floats have a decimal.
- For Playdate specifically, they are 32 bit.
- Strings
- You can make a string with “double” and ‘single’ quotes.
- UserData
- This is the data type when you’re talking to the C language.
- Functions
- Make it so you can reuse code.
- First class citizens. You can pass functions around just like any other data.
- Tables
- Tables are THE data structure in Lua. Access by key.value or key[index]
- Tables are 1 indexed if no key is provided.
- Nil
- Nothing is nil except nil because nil is nothing.
Lodomo.Dev is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.
References
Lua Docs – https://www.lua.org/docs.html
Lua Reference Manual – https://www.lua.org/manual/
Playdate SDK – https://play.date/dev/
Ascii Table – https://www.asciitable.com/

Leave a Reply