Lua in the NetBSD Kernel
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
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
The Lua function
function hello()
print(‘Hello, world!’)
end
Call hello from C:
lua_getglobal(L, « hallo »);
lua_pcall(L, 0, 0, 0);
Ideas for Users
Modifying software written in C is hard for users
Give users the power to modify and extend the system
Let users explore the system in an easy way
Ideas for Developers
,,Rapid Application Development » approach to driver development
Modifying the system behaviour
Conguration of kernel subsystems
Alternatives
Python
Java
Python
Not to dicult to integrate in C
Huge library
Memory consumption
Dicult object mapping
Java
Easy to integrate
Dicult object mapping
Memory considerations
Has been used for driver development
Lua in NetBSD Userland
Library (liblua.so) and binaries (lua, luac) committed to current
Will be part of NetBSD 6
No back port to NetBSD 5 stable planned
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