Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Lua Quick Start Guide

You're reading from  Lua Quick Start Guide

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781789343229
Pages 202 pages
Edition 1st Edition
Languages
Author (1):
Gabor Szauer Gabor Szauer
Profile icon Gabor Szauer

Properties

A property is a mix between a function and a variable. Properties are similar to C#'s getter/setter system. To Lua, a property looks like a normal variable, but every time that variable is read, a function is called. Similarly, every time the variable is changed, a function is called. These are getter/setter functions. If a property has a getter function but no setter, it is effectively read-only.

A property can be added with the addProperty (char const*, TG (T::*) () const, void (T::*) function. This function takes three arguments. The first one is the Lua name for the variable, and the second and third arguments are getter and setter functions, respectively. The addProperty function has an overloaded version that only takes a getter function. The following code demonstrates how to use properties:

int bar;
int get_bar () const {
// Potentially do some error...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}