↓ Skip to main content
  1. Home projects/

luaBox2D: Box2D physics for Lua

··

I wrote luaBox2D to expose the Box2D 2D physics engine to Lua, and it became the physics layer behind the Lua-scripted games in Cinder Climb.

Nearly the whole Box2D API has a Lua counterpart, from worlds, bodies and fixtures through every shape and joint type to contacts, ray casts, queries and filters, so a Lua script reads almost like the C++ “Hello World” from the Box2D manual:

A Lua game script calls the luaBox2D bindings, written in C++, which wrap the Box2D physics engine.Lua game scriptworlds, bodies, jointsluaBox2Dbindings in C++, Lua 5.1Box2D2D physics enginenearly the whole Box2D API has a Lua counterpart
Where luaBox2D sits between a Lua script and Box2D
local box2d = require 'LuaBox2D'
local world = box2d.World(box2d.Vec2(0, -10))

local bodyDef = box2d.BodyDef()
bodyDef.type = 'dynamic'
bodyDef.position = box2d.Vec2(0, 4)
local body = world.createBody(bodyDef)

The bindings are written in C++ and built with CMake against Lua 5.1, and there are Lua tests for the main classes in the repository.

Source on GitHub.

Related