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

Constructor

Lua Bridge only supports a single constructor. Overloaded constructors are not possible to declare with Lua Bridge. A constructor can be added with the addConstructor function. The function signature of the constructor must be specified as a template argument, since a class may have multiple overloaded constructors. The following code shows a C++ class with three constructors, but only the one that takes three floats is exposed to Lua:

class Vec3 {  public:    Vec3();    Vec3(const Vec3& other);    Vec3(float x, float y, float z);}getGlobalNamespace(L)    .beginNamespace("Math")      .beginClass<Vec3>("Vec3")        .addConstructor<void (*) (float, float, float)>()      .endClass()    .endNamespace();
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