Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Working with tables in C

Up until now, we have only been working with basic Lua types and functions. Lua's C API also allows us to work with tables. A new table can be created with the lua_newtable (lua_State*) function. This function returns nothing and only takes the Lua state as an argument. The lua_newtable function will create an empty table and leave it on top of the stack. Once the table is on the stack, it's up to you to assign it to a variable. For example, the following code creates a table named "vector" that has global scope:

lua_newtable(L);lua_setglobal(L, "vector");

The C API for working with tables can get a little verbose. There are a few libraries that address this and aim to reduce the amount of code you have to actually ...

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.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content