Embedding Lua in C Programs

1 The Programming Language Lua
The Lua Interpreter
Syntax and such
Modules
2 Embedding Lua in C Programs
State Manipulation
Calling C from Lua
Calling Lua from C
3 Lua in the NetBSD Kernel
Use Cases
Implementation Overview
Implementation Details

The Programming Language Lua

The Lua Interpreter
Running from C
 int luaL do le(lua State *L, const char * lename)
 int luaL dostring(lua State *L, const char *str)
Syntax and such
Values, Variables, and, Data Types
 Variables have no type
 Values do have a type
 Functions are rst-class values
Tables
 Tables are THE data structure in Lua
 Nice constructor syntax
 Tables make Lua a good DDL
 Metatables can be associated with every object
Lua Table Constructor
Create and initialize a table, access a eld:
mytable = {
name = ‘Marc’,
surname = ‘Balmer’,
email = ‘m@x.org’
}
print(mytable.email)
Modules
Extending Lua Programs
Acess GPIO pins from Lua:
require ‘gpio’
g = gpio.open(‘/dev/gpio0’)
g:write(4, gpio.PIN_HIGH)
g:close()

Embedding Lua in C Programs

State Manipulation
Calling a C Function
 Function has been registered in luaopen module()
 int function(lua State *L)
 Parameters popped from the stack
 Return values pushed on the stack
 Return Nr. of return values
Calling a Lua Function
 Find the function and make sure is *is* a function
 Push parameters on the stack
 Use lua call(lua State *L, int index)
 or lua pcall(lua State *L, int index)
 Pop return values from the stack


Si le lien ne fonctionne pas correctement, veuillez nous contacter (mentionner le lien dans votre message)
Lua in the NetBSD Kernel (1,37 MO) (Cours PDF)
Cours Lua

Télécharger aussi :

Laisser un commentaire

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