Skip to Content
Creating Solid APIs with Lua
book

Creating Solid APIs with Lua

by Tyler Neylon
February 2017
Intermediate to advanced
133 pages
2h 43m
English
O'Reilly Media, Inc.
Content preview from Creating Solid APIs with Lua

Chapter 1. Running a Lua Script from C

In the first part of this book, the focus is on understanding the data and control flows between Lua and C. After those ideas have been established, we’ll be ready to tackle security in the second part, which begins with Chapter 5.

An Overview of the C/Lua Interface

Many programming languages are distributed in the form of a language-specific compiler or interpreter. Lua, on the other hand, is essentially distributed as a C API. Many users interact with Lua by using the official interpreter, but even this interpreter is built on top of the C API, without any special access to the language’s implementation. In other words, Lua is not only written in C; it is also written to be used from C.

Lua’s C API can create or destroy entire runtime environments, which are referred to as Lua states. A Lua state is a C pointer to an opaque data structure. This structure knows everything about a running Lua environment, including all global values, closures, coroutines, and loaded modules. Virtually every function in Lua’s C API accepts a Lua state as its first parameter.

Because Lua states are opaque structures, we need to use API functions to access the Lua values stored within a state. To this end, every Lua state has a Lua stack, which is a container for Lua values such as Lua strings or tables. You can think of the Lua stack as a window into the set of Lua values currently relevant to your C code. We’ll dive into all the relevant details of this stack ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Integrate Lua with C++

Integrate Lua with C++

Wenhuan Li
Create a Vim Plugin

Create a Vim Plugin

Alfredo Deza, Noah Gift
PHP Cookbook

PHP Cookbook

Eric A. Mann

Publisher Resources

ISBN: 9781491986301