root / lab4 / .minix-src / include / sys / lua.h @ 14
History | View | Annotate | Download (3.17 KB)
1 | 13 | up20180614 | /* $NetBSD: lua.h,v 1.8 2015/09/06 06:01:02 dholland Exp $ */
|
---|---|---|---|
2 | |||
3 | /*
|
||
4 | * Copyright (c) 2014 by Lourival Vieira Neto <lneto@NetBSD.org>.
|
||
5 | * Copyright (c) 2011, 2013 Marc Balmer <mbalmer@NetBSD.org>.
|
||
6 | * All rights reserved.
|
||
7 | *
|
||
8 | * Redistribution and use in source and binary forms, with or without
|
||
9 | * modification, are permitted provided that the following conditions
|
||
10 | * are met:
|
||
11 | * 1. Redistributions of source code must retain the above copyright
|
||
12 | * notice, this list of conditions and the following disclaimer.
|
||
13 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
14 | * notice, this list of conditions and the following disclaimer in the
|
||
15 | * documentation and/or other materials provided with the distribution.
|
||
16 | * 3. The name of the Author may not be used to endorse or promote products
|
||
17 | * derived from this software without specific prior written permission.
|
||
18 | *
|
||
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
29 | * SUCH DAMAGE.
|
||
30 | */
|
||
31 | |||
32 | #ifndef _SYS_LUA_H_
|
||
33 | #define _SYS_LUA_H_
|
||
34 | |||
35 | #include <sys/param.h> |
||
36 | #include <sys/ioccom.h> |
||
37 | |||
38 | #include <lua.h> /* for lua_State */ |
||
39 | |||
40 | #ifdef _KERNEL
|
||
41 | #include <sys/condvar.h> |
||
42 | #endif
|
||
43 | |||
44 | #define MAX_LUA_NAME 16 |
||
45 | #define MAX_LUA_DESC 64 |
||
46 | #define LUA_MAX_MODNAME 32 |
||
47 | |||
48 | struct lua_state_info {
|
||
49 | char name[MAX_LUA_NAME];
|
||
50 | char desc[MAX_LUA_DESC];
|
||
51 | bool user;
|
||
52 | }; |
||
53 | |||
54 | struct lua_info {
|
||
55 | int num_states; /* total number of created Lua states */ |
||
56 | struct lua_state_info *states;
|
||
57 | }; |
||
58 | |||
59 | struct lua_create {
|
||
60 | char name[MAX_LUA_NAME];
|
||
61 | char desc[MAX_LUA_DESC];
|
||
62 | }; |
||
63 | |||
64 | struct lua_require {
|
||
65 | char state[MAX_LUA_NAME];
|
||
66 | char module[LUA_MAX_MODNAME];
|
||
67 | }; |
||
68 | |||
69 | struct lua_load {
|
||
70 | char state[MAX_LUA_NAME];
|
||
71 | char path[MAXPATHLEN];
|
||
72 | }; |
||
73 | |||
74 | #define LUAINFO _IOWR('l', 0, struct lua_info) |
||
75 | |||
76 | #define LUACREATE _IOWR('l', 1, struct lua_create) |
||
77 | #define LUADESTROY _IOWR('l', 2, struct lua_create) |
||
78 | |||
79 | /* 'require' a module in a state */
|
||
80 | #define LUAREQUIRE _IOWR('l', 3, struct lua_require) |
||
81 | |||
82 | /* loading Lua code into a Lua state */
|
||
83 | #define LUALOAD _IOWR('l', 4, struct lua_load) |
||
84 | |||
85 | #ifdef _KERNEL
|
||
86 | extern int klua_mod_register(const char *, lua_CFunction); |
||
87 | extern int klua_mod_unregister(const char *); |
||
88 | |||
89 | typedef struct _klua_State { |
||
90 | lua_State *L; |
||
91 | kmutex_t ks_lock; |
||
92 | bool ks_user; /* state created by user (ioctl) */ |
||
93 | } klua_State; |
||
94 | |||
95 | extern void klua_lock(klua_State *); |
||
96 | extern void klua_unlock(klua_State *); |
||
97 | |||
98 | extern void klua_close(klua_State *); |
||
99 | extern klua_State *klua_newstate(lua_Alloc, void *, const char *, const char *, |
||
100 | int);
|
||
101 | extern klua_State *kluaL_newstate(const char *, const char *, int); |
||
102 | #endif
|
||
103 | |||
104 | #endif /* _SYS_LUA_H_ */ |