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

Reading global variables

Reading a global variable is done in three steps. You have to use the name of the variable to push its value onto the stack. Once on the stack, the value can be read by C. After you have the value in C, clean up the stack by removing the old copy.

You can push a global variable onto the stack by name using the lua_getglobal (lua_State*, const char *) function. The first argument of lua_getglobal is the Lua state. The second argument is the name of the variable to push it onto the stack. This function does not return anything.

The lua_getglobal function uses the name of a global variable to leave its value on the stack. To read the value in C, you have to use one of the lua_to functions such as lua_tonumber or lua_tostring ...

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