Book description
Learn how you can build APIs by integrating the Lua and C programming languages. These APIs can be used to speed up development within your company, allow people to customize your app or game, and serve as the foundation of a domain-specific language within a platform you’re developing.
Author Tyler Neylon—a game designer with a PhD in applied math—shows you how C and Lua interface with each other, so you can create a set of Lua classes and functions that work programmatically with local applications. You’ll also learn how to guard against shady scripts written by users who either make mistakes or purposefully attempt to break your system.
- Build Lua from source, then link the Lua library to a C program that can execute a Lua script
- Write Lua-visible functions with the power of C by calling C functions from Lua
- Work with Lua data types from C
- Add Lua classes to your API, implemented in either Lua or C
- Manage Lua exceptions with error-handling functions, and add custom hook functions that can protect you from common programming errors
- Give users the freedom to write their own scripts that can be run in a C-created sandboxed environment
Lua is easy to learn, especially if you know JavaScript. Neylon’s free 3-part series on oreilly.com, Learn Lua from JavaScript, will help you get started.
Table of contents
- Preface
- I. Making a Lua API
- 1. Running a Lua Script from C
- 2. Calling C from Lua
- 3. Using Lua Values in C
- 4. Making Your API Classy
- II. Script Safety
-
5. Detecting Errors
- Throwing and Catching Errors in Lua
- When Should You Throw an Exception?
- Don’t Panic!
- How lua_pcall() Handles Errors
- Turtles All the Way Down
- Getting Strict About Globals and Typos
- The Environment of Freshly Loaded Chunks
- A Version of strict.lua
- EatyGuy Version 9: Death, Strictly
- A Brief but Quickly Dismissed Question of Morality
- 6. Sandboxing User Scripts
Product information
- Title: Creating Solid APIs with Lua
- Author(s):
- Release date: February 2017
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491963760
You might also like
book
Tidy First?
Messy code is a nuisance. "Tidying" code, to make it more readable, requires breaking it up …
book
Deciphering Data Architectures
Data fabric, data lakehouse, and data mesh have recently appeared as viable alternatives to the modern …
book
Fluent React
When it comes to building user interfaces on the web, React enables web developers to unlock …
book
Generative Deep Learning, 2nd Edition
Generative AI is the hottest topic in tech. This practical book teaches machine learning engineers and …