Lua & C++ Snake

gameplay_01.png

Overview

This project is a small C++ framework built around Lua using the Sol2 library. It acts as a lightweight runtime that can automatically load and run Lua-based games. The framework exposes core functionality like rendering, input, and drawing to Lua, letting scripts define their own game logic without touching the C++ side. It was a great exercise in building a bridge between scripting and native code while keeping the setup simple and flexible.

Core
cplusplus

cplusplus

Libraries
sol

sol


Code Snippets

This is the main lua file that initializes the game, sets up the window, and contains the main game loop. The game loop handles input, updates the game state, and renders the game each frame.

In this part of the code, I set up all Lua bindings for my engine using Sol2. It exposes key C++ classes like ColorRGB, Bitmap, and GameEngine to Lua, allowing scripts to create objects, call engine functions, and interact with the rendering and game logic directly. To keep it organized, I grouped everything inside Game::CreateLuaBindings(), which handles all the registrations in one place.