Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Lua Quick Start Guide

You're reading from   Lua Quick Start Guide The easiest way to learn Lua programming

Arrow left icon
Product type Paperback
Published in Jul 2018
Publisher Packt
ISBN-13 9781789343229
Length 202 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Gabor Szauer Gabor Szauer
Author Profile Icon Gabor Szauer
Gabor Szauer
Arrow right icon
View More author details
Toc

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 $19.99/month. Cancel anytime