My implementation of game states library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
Posts: 1
Joined: Fri May 08, 2020 8:42 pm

My implementation of game states library

Post by Spellweaver » Fri May 08, 2020 9:00 pm

Hello dear Love2d community. Some time ago I've created a small states.lua lib for personal use and used that in every single of my project afterwards. Thought I might as well publish it separately on github and share with people in case they find it useful.

Here's the github link:

I would be really happy if it turns out useful for someone besides me, or if someone provides useful feedback on the code.

How to use

In main.lua
states = require("states")
in love.load() call states.setup()
From now on, states library will redirect love2d callbacks from your main.lua to state files
Each state file should be located in "states/" directory and return a table of callbacks that correspond to love2d callbacks
If you want your callbacks to be state-independant, keep them in your main.lua. This way states library will not redirect them to states.
If you want a callback to have both state-dependant and state-independant part,
keep it in main.lua and call states.(callback name) within love 2d callback
To switch states (you should probably do this immediately after initialising) use states.switch(filename,params)
Filename is a name of your state file, while params is a table that will be caught by .open callback within according state file
Through params you can transfer data to your state files conveniently

User avatar
Posts: 25
Joined: Wed Nov 27, 2019 9:19 pm
Location: Almeria, ES

Re: My implementation of game states library

Post by JuanjoSalvador » Tue Sep 15, 2020 5:13 pm

Can you provide a code example? profile - When I'm uploading my works and devblogs
GitHub - All my code is here!
Horchata - A set of Lua modules I wrote to make some task easier

Posts: 31
Joined: Sun Aug 16, 2020 1:28 pm

Re: My implementation of game states library

Post by RNavega » Thu Sep 17, 2020 12:26 pm

The code looks interesting, thanks for sharing!

Post Reply

Who is online

Users browsing this forum: pirogronian and 28 guests