↓ Skip to main content
  1. Home projects/

luaBox2D: Box2D physics for Lua

··

luaBox2D gives Lua access to the Box2D 2D physics engine. It is the physics layer behind the Lua-scripted games in Cinder Climb.

Nearly the whole Box2D API has a Lua counterpart: worlds, bodies, fixtures, all shape and joint types, contacts, ray casts, queries and filters. A Lua script reads almost like the C++ “Hello World” from the Box2D manual:

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 C++, built with CMake against Lua 5.1. The repository has Lua tests for the main classes.

Source on GitHub.

Related