Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: lua.h,v 1.9 2023/07/11 14:57:21 martin Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2014 by Lourival Vieira Neto <lneto (at) NetBSD.org>.
      5  * Copyright (c) 2011, 2013 Marc Balmer <mbalmer (at) 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 #include <sys/mutex.h>
     43 #endif
     44 
     45 #define MAX_LUA_NAME		16
     46 #define MAX_LUA_DESC		64
     47 #define LUA_MAX_MODNAME		32
     48 
     49 struct lua_state_info {
     50 	char	name[MAX_LUA_NAME];
     51 	char	desc[MAX_LUA_DESC];
     52 	bool	user;
     53 };
     54 
     55 struct lua_info {
     56 	int num_states;		/* total number of created Lua states */
     57 	struct lua_state_info *states;
     58 };
     59 
     60 struct lua_create {
     61 	char	name[MAX_LUA_NAME];
     62 	char	desc[MAX_LUA_DESC];
     63 };
     64 
     65 struct lua_require {
     66 	char	state[MAX_LUA_NAME];
     67 	char	module[LUA_MAX_MODNAME];
     68 };
     69 
     70 struct lua_load {
     71 	char	state[MAX_LUA_NAME];
     72 	char	path[MAXPATHLEN];
     73 };
     74 
     75 #define LUAINFO		_IOWR('l', 0, struct lua_info)
     76 
     77 #define LUACREATE	_IOWR('l', 1, struct lua_create)
     78 #define LUADESTROY	_IOWR('l', 2, struct lua_create)
     79 
     80 /* 'require' a module in a state */
     81 #define LUAREQUIRE	_IOWR('l', 3, struct lua_require)
     82 
     83 /* loading Lua code into a Lua state */
     84 #define LUALOAD		_IOWR('l', 4, struct lua_load)
     85 
     86 #ifdef _KERNEL
     87 extern int klua_mod_register(const char *, lua_CFunction);
     88 extern int klua_mod_unregister(const char *);
     89 
     90 typedef struct _klua_State {
     91 	lua_State	*L;
     92 	kmutex_t	 ks_lock;
     93 	bool		 ks_user;	/* state created by user (ioctl) */
     94 } klua_State;
     95 
     96 extern void klua_lock(klua_State *);
     97 extern void klua_unlock(klua_State *);
     98 
     99 extern void klua_close(klua_State *);
    100 extern klua_State *klua_newstate(lua_Alloc, void *, const char *, const char *,
    101 		int);
    102 extern klua_State *kluaL_newstate(const char *, const char *, int);
    103 #endif
    104 
    105 #endif /* _SYS_LUA_H_ */
    106