Installer import into contrib (real import this time)
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / lib / lua / dfui / lua_dfui.h
1 /*
2  * Copyright (c) 2004 Scott Ullrich <GeekGod@GeekGod.com> 
3  * Portions Copyright (c) 2004 Chris Pressey <cpressey@catseye.mine.nu>
4  *
5  * Copyright (c) 2004 The DragonFly Project.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The DragonFly Project
9  * by Scott Ullrich and Chris Pressey (see above for e-mail addresses).
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in
20  *    the documentation and/or other materials provided with the
21  *    distribution.
22  *
23  * 3. Neither the name of The DragonFly Project nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific, prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
31  * COPYRIGHT HOLDERS, CONTRIBUTORS OR VOICES IN THE AUTHOR'S HEAD
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY
33  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
34  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
40  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
41  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
43  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  */
48
49 /* 
50  * lua_dfui.h
51  * $Id: lua_dfui.h,v 1.69 2005/02/22 07:16:48 cpressey Exp $
52  */
53
54 #ifndef _LUA_DFUI_H_
55 #define _LUA_DFUI_H_
56
57 /*
58  * Macro to define a function that checks that the Lua
59  * data object at `index' on Lua's stack is a userdata object
60  * of Lua type `sname' and C type `type'.
61  * If not, the function throws a Lua error, but if so,
62  * it returns the object.
63  */
64 #define LUA_CHECK_FUNCTION(name, sname, type)                           \
65 type    lua_check_##name(lua_State *, int);                             \
66 type                                                                    \
67 lua_check_##name(lua_State *L, int ch_index)                            \
68 {                                                                       \
69         luaL_checktype(L, ch_index, LUA_TUSERDATA);                     \
70         lua_getmetatable(L, ch_index);                                  \
71         lua_pushliteral(L, sname "Meta");                               \
72         lua_rawget(L, LUA_GLOBALSINDEX);                                \
73         if (!lua_rawequal(L, -1, -2))                                   \
74                 luaL_typerror(L, ch_index, sname);                      \
75         lua_pop(L, 2);                                                  \
76         return((type)lua_unboxpointer(L, ch_index));                    \
77 }
78
79 /*
80  * Macro to definate a function which pushes a
81  * Lua `sname' object onto Lua's stack.
82  */
83 #define LUA_PUSH_FUNCTION(name, sname, type)                            \
84 type lua_push_##name(lua_State *, type);                                \
85 type                                                                    \
86 lua_push_##name(lua_State *L, type x)                                   \
87 {                                                                       \
88         lua_boxpointer(L, x);                                           \
89         lua_pushliteral(L, sname "Meta");                               \
90         lua_gettable(L, LUA_GLOBALSINDEX);                              \
91         lua_setmetatable(L, -2);                                        \
92         return(x);                                                      \
93 }
94
95 struct dfui_connection;
96
97 void     lua_set_instance_handler(lua_State *L,
98             const char *table_name, const char *metatable_name);
99 const char *lua_access_table_string(lua_State *, int, const char *);
100 void     lua_show_debug(lua_State *);
101 void     lua_pushfileptr(lua_State *, FILE *);
102
103 LUA_API int     lua_dfui_register(lua_State *);
104 LUA_API int     lua_dfui_progress_register(lua_State *);
105
106 LUA_API int     luaopen_ldfui(lua_State *);
107
108 #endif  /* !_DFUIBE_LUA_H_ */