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

Member variables, properties, and functions

Adding variables, properties, and functions to a class in Lua Bridge is done in the same fashion as adding any of these things to a namespace. The functions are addData, addFunction, and addProperty. None of these functions require any template data, but the data they point to does have to be scoped to the class it belongs to. The following code sample shows how to use these methods:

class Vec3 {  public:    float x, y, z;  float Magnitude() const;  void Normalize();}getGlobalNamespace(L)    .beginNamespace("Math")        .beginClass<Vec3>("Vec3")            .addData("x", &Vec3::x)            .addData("y", &Vec3::y)            .addData("z", &Vec3::z)            .addProperty("Magnitude", &Vec3::Magnitude)            .addFunction("Normalize", &Vec3::Normalize) .endClass() ...
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