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

Reading Lua variables from C

It's very easy to read and write Lua variables from C. Because of this, Lua is often used as a configuration language or to save and load the state of a program. The Lua runtime will parse and interpret files for you, removing the need for manual parsing. And the syntax of Lua lends itself very well to these kinds of tasks. In this section, we're going to explore how to read Lua variables that are used as configuration data.

Loading a Lua file

To read a Lua variable in C, you will need to load the Lua file with int luaL_loadfile(lua_State*, const char*). The resulting chunk will then need to be executed with lua_pcall(lua_State*, int, int, int, int). After the Lua chunk is loaded and...

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}