xref: /netbsd-src/share/man/man9/klua_mod_register.9 (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1.\"	$NetBSD: klua_mod_register.9,v 1.5 2017/04/16 06:34:05 wiz Exp $
2.\"
3.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Kamil Rytarowski.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd April 15, 2017
31.Dt KLUA_MOD_REGISTER 9
32.Os
33.Sh NAME
34.Nm klua_mod_register ,
35.Nm klua_mod_unregister
36.Nd Lua kernel bindings
37.Sh SYNOPSIS
38.In sys/lua.h
39.Ft void
40.Fn klua_mod_register "const char *name" "lua_CFunction open"
41.Ft void
42.Fn klua_mod_unregister "const char *name"
43.Sh DESCRIPTION
44The Lua kernel bindings are designed to provide functionality to Lua scripts
45normally not available in the language itself, e.g. to access core kernel functionality.
46This is achieved by utilizing the lua_modules functionality.
47.Pp
48The lua_module structure is declared as follows:
49.Bd -literal
50struct lua_module {
51        char                    mod_name[LUA_MAX_MODNAME];
52        lua_CFunction           open;
53        int                     refcount;
54        LIST_ENTRY(lua_module)  mod_next;
55};
56.Ed
57.Pp
58The
59.Ft mod_name
60defines the unique name of a module.
61A C function must use the standard Lua protocol in order to communicate with
62Lua, this part is maintained with the
63.Ft open
64element in the standard Lua way.
65.Ft refcount
66protects the module from being unloaded whilst still in use.
67The last parameter,
68.Ft mod_next ,
69is used for the standard container
70.Xr LIST 3 .
71.Pp
72The
73.Fn klua_mod_register
74function registers a new function which is made available to the
75.Xr lua 9
76device and Lua code using the
77.Dv require
78directive.
79The
80.Dv require
81directive can be called from
82.Xr luactl 8
83and the kernel Lua version.
84The
85.Fa name
86parameter is a unique identifier of the kernel Lua module.
87.Fa open
88points to a function used in the C to Lua binding,
89defined with the appropriate standard Lua API.
90.Pp
91Once registered, a C function can be unregistered with the
92.Fn klua_mod_unregister
93function.
94This function takes as its parameter the unique literal identifier of the
95extending module.
96.Sh EXAMPLES
97A set of example modules is available in the
98.Pa src/sys/modules/examples
99directory hierarchy.
100.Sh SEE ALSO
101.Xr lua 1 ,
102.Xr luac 1 ,
103.Xr intro 3lua ,
104.Xr lua 4 ,
105.Xr klua_close 9 ,
106.Xr klua_lock 9 ,
107.Xr klua_newstate 9 ,
108.Xr klua_unlock 9 ,
109.Xr kluaL_newstate 9 ,
110.Xr intro 9lua
111.Sh AUTHORS
112.An Kamil Rytarowski Aq Mt kamil@NetBSD.org .
113