Home Page Icon
Home Page
Table of Contents for
I. Making a Lua API
Close
I. Making a Lua API
by Tyler Neylon
Creating Solid APIs with Lua
Preface
Acknowledgments
I. Making a Lua API
1. Running a Lua Script from C
An Overview of the C/Lua Interface
An Example: EatyGuy
Getting the Lua Source
If You’re Using macOS or Linux…
If You’re Using Windows…
This Book’s GitHub Repo
Running a Lua Script from C
Lua Modules and Loading Them from C
Drawing Mazes
One Way to Call a Lua Function from C
Stack Indexes
Giving Lua the Power of C
2. Calling C from Lua
EatyGuy Version 1: A Lua-Callable C Function
The tput Shell Command
The Core Mechanics of Lua-Callable C Functions
EatyGuy Version 2: Adding an Animated Player
Strings and Multiple Arguments with set_color() and set_pos()
Sending a Return Value from C to Lua by Using timestamp()
Fancier Maze Drawing
Starting, Stopping, and Sharing Functions with Lua
Game State and Lua’s Event Loop
Updating Player State
Drawing the Player State
Calling Lua Functions from C More Effectively
3. Using Lua Values in C
EatyGuy Version 3: Passing Data to a Lua Function
Receiving Arrow Key Presses
EatyGuy Version 4: Implementing API Functions Within Lua
Fixing the tput Bottleneck
EatyGuy Version 5: Working with Lua Tables from C
Where Tables Live
The Primary Table Functions
Using a Table to Send Game State to Lua
Adding Some Class to Your API
4. Making Your API Classy
EatyGuy Version 6: Writing a Class in Lua
A Common Code Pattern for Lua Classes
The Character Class Example
EatyGuy Version 7: Class Inheritance
Subclasses in Lua
The Baddy Class
EatyGuy Version 8: Introducing the userdata Type
Writing a Lua-Loadable Module in C
Implementing a Class-Like userdata Type
Integrating a C Module into Your API
Making Your Code Debug-Friendly
II. Script Safety
5. Detecting Errors
Throwing and Catching Errors in Lua
When Should You Throw an Exception?
Don’t Panic!
Lua Errors in C
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
EatyGuy Version 10: The Baddy Construction Kit
The Code of Scum and Villainy
Scripts Gone Wild
Controlling Library Access
Managing Memory Use
Managing CPU Use
End == Nigh
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Preface
Next
Next Chapter
1. Running a Lua Script from C
Part I.
Making a Lua API
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset