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

Creating Lua variables from C

Communicating with Lua is one way. In addition to reading Lua variables from C, you can also create Lua variables from C. The process for doing so is simple: you push a value onto the stack, then tell the Lua runtime to assign that value to a variable by name.

To create a variable, use the lua_setglobal (lua_State*, const char*) function. This function returns nothing. Its first argument is the Lua state to work on, the second argument is the name of the global variable to assign. This function will pop the top value off the stack and assign it to the name of the variable specified.

Let's take the example from the last section and reverse it. This time, the variables for class, attack, and defense are going to ...

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