Reader small image

You're reading from  Lua Quick Start Guide

Product typeBook
Published inJul 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781789343229
Edition1st Edition
Languages
Right arrow
Author (1)
Gabor Szauer
Gabor Szauer
author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer

Right arrow

Namespaces

Everything inside Lua Bridge must be declared within a namespace. These namespaces have no connection to C++ namespaces, and within Lua, they are just tables. The concept of a namespace is similar to the concept of a Lua module being loaded as a table.

A global namespace exists, and you can register functions, variables, and classes to that namespace, but it's considered bad practice. You can get the global namespace with the following call:

getGlobalNamespace(lua_State*)

Once you have the global namespace, you can create your own namespace inside it with the beginNamespace(const char*) call. This function takes a string with the name of the namespace as an argument. Once you are done working with the namespace, you must close it with the endNameSpace() call. If you want to add more classes in different parts of the code in a namespace, it can be opened multiple...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Lua Quick Start Guide
Published in: Jul 2018Publisher: PacktISBN-13: 9781789343229

Author (1)

author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer