Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Classes

The beginClass/endClass functions can be used to expose classes to Lua. The class type must be provided as a template argument to the beginClass function. You can call beingClass/endClass multiple times for the same class, and on each call, new methods and variables can be added. Suppose that a class named Vec3 exists, to represent a 3D vector. It can be exposed to Lua using Lua Bridge, as follows:

class Vec3 { };getGlobalNamespace(L)    .beginNamespace("Math")        .beginClass<Vec3>("Vec3")        .endClass()    .endNamespace()

To create a new object, just call the name of the class as a function. For example, the preceding code can create a new Vec3 with the following code:

local vector = Math.Vec3()
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content