The Lua-C API

Extrait du cours the Lua-C API

Multiple Lua States
A state is completely self-contained
A program can have multiple, independent Lua states
Allows a lightweight implementation of Lua processes
each process is a Lua state
multiple workers (C threads) run those processes
communication through message passing
Lua Values
Most APIs use some kind of “Value” type in C
to represent values in the language
PyObject (Python), jobject (JNI)
Problem: garbage collection
easy to create dangling references and memory leaks
Lua Values
The Lua API has no LuaObject type
A Lua object lives only inside Lua
Two structures keep objects used by C:
the registry
the stack
The registry is a regular Lua table always
accessible by the API
The Stack
Keeps all Lua objects in use by a C function
Each function has its own private stack
Data Exchange
The stack is the only channel for exchanging
data between C and Lua
Injection functions
convert a C value into a Lua value
push the result into the stack
Projection functions
convert a Lua value into a C value
get the Lua value from anywhere in the stack
negative indices index from the top
…….

Si le lien ne fonctionne pas correctement, veuillez nous contacter (mentionner le lien dans votre message)
The Lua-C API (80,0 KO) (Cours PDF)

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *