Imported from ../lua-4.0.1.tar.gz.
[lua.git] / include / lua.h
blob660ecd80a141c05a44f72386198149b945b3d8b1
1 /*
2 ** $Id: lua.h,v 1.79a 2000/10/31 12:44:07 roberto Exp $
3 ** Lua - An Extensible Extension Language
4 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5 ** e-mail: lua@tecgraf.puc-rio.br
6 ** www: http://www.tecgraf.puc-rio.br/lua/
7 ** See Copyright Notice at the end of this file
8 */
11 #ifndef lua_h
12 #define lua_h
15 /* definition of `size_t' */
16 #include <stddef.h>
19 /* mark for all API functions */
20 #ifndef LUA_API
21 #define LUA_API extern
22 #endif
25 #define LUA_VERSION "Lua 4.0.1"
26 #define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
27 #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
30 /* name of global variable with error handler */
31 #define LUA_ERRORMESSAGE "_ERRORMESSAGE"
34 /* pre-defined references */
35 #define LUA_NOREF (-2)
36 #define LUA_REFNIL (-1)
37 #define LUA_REFREGISTRY 0
39 /* pre-defined tags */
40 #define LUA_ANYTAG (-1)
41 #define LUA_NOTAG (-2)
44 /* option for multiple returns in lua_call */
45 #define LUA_MULTRET (-1)
48 /* minimum stack available for a C function */
49 #define LUA_MINSTACK 20
52 /* error codes for lua_do* */
53 #define LUA_ERRRUN 1
54 #define LUA_ERRFILE 2
55 #define LUA_ERRSYNTAX 3
56 #define LUA_ERRMEM 4
57 #define LUA_ERRERR 5
60 typedef struct lua_State lua_State;
62 typedef int (*lua_CFunction) (lua_State *L);
65 ** types returned by `lua_type'
67 #define LUA_TNONE (-1)
69 #define LUA_TUSERDATA 0
70 #define LUA_TNIL 1
71 #define LUA_TNUMBER 2
72 #define LUA_TSTRING 3
73 #define LUA_TTABLE 4
74 #define LUA_TFUNCTION 5
79 ** state manipulation
81 LUA_API lua_State *lua_open (int stacksize);
82 LUA_API void lua_close (lua_State *L);
86 ** basic stack manipulation
88 LUA_API int lua_gettop (lua_State *L);
89 LUA_API void lua_settop (lua_State *L, int index);
90 LUA_API void lua_pushvalue (lua_State *L, int index);
91 LUA_API void lua_remove (lua_State *L, int index);
92 LUA_API void lua_insert (lua_State *L, int index);
93 LUA_API int lua_stackspace (lua_State *L);
97 ** access functions (stack -> C)
100 LUA_API int lua_type (lua_State *L, int index);
101 LUA_API const char *lua_typename (lua_State *L, int t);
102 LUA_API int lua_isnumber (lua_State *L, int index);
103 LUA_API int lua_isstring (lua_State *L, int index);
104 LUA_API int lua_iscfunction (lua_State *L, int index);
105 LUA_API int lua_tag (lua_State *L, int index);
107 LUA_API int lua_equal (lua_State *L, int index1, int index2);
108 LUA_API int lua_lessthan (lua_State *L, int index1, int index2);
110 LUA_API double lua_tonumber (lua_State *L, int index);
111 LUA_API const char *lua_tostring (lua_State *L, int index);
112 LUA_API size_t lua_strlen (lua_State *L, int index);
113 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index);
114 LUA_API void *lua_touserdata (lua_State *L, int index);
115 LUA_API const void *lua_topointer (lua_State *L, int index);
119 ** push functions (C -> stack)
121 LUA_API void lua_pushnil (lua_State *L);
122 LUA_API void lua_pushnumber (lua_State *L, double n);
123 LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len);
124 LUA_API void lua_pushstring (lua_State *L, const char *s);
125 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
126 LUA_API void lua_pushusertag (lua_State *L, void *u, int tag);
130 ** get functions (Lua -> stack)
132 LUA_API void lua_getglobal (lua_State *L, const char *name);
133 LUA_API void lua_gettable (lua_State *L, int index);
134 LUA_API void lua_rawget (lua_State *L, int index);
135 LUA_API void lua_rawgeti (lua_State *L, int index, int n);
136 LUA_API void lua_getglobals (lua_State *L);
137 LUA_API void lua_gettagmethod (lua_State *L, int tag, const char *event);
138 LUA_API int lua_getref (lua_State *L, int ref);
139 LUA_API void lua_newtable (lua_State *L);
143 ** set functions (stack -> Lua)
145 LUA_API void lua_setglobal (lua_State *L, const char *name);
146 LUA_API void lua_settable (lua_State *L, int index);
147 LUA_API void lua_rawset (lua_State *L, int index);
148 LUA_API void lua_rawseti (lua_State *L, int index, int n);
149 LUA_API void lua_setglobals (lua_State *L);
150 LUA_API void lua_settagmethod (lua_State *L, int tag, const char *event);
151 LUA_API int lua_ref (lua_State *L, int lock);
155 ** "do" functions (run Lua code)
157 LUA_API int lua_call (lua_State *L, int nargs, int nresults);
158 LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults);
159 LUA_API int lua_dofile (lua_State *L, const char *filename);
160 LUA_API int lua_dostring (lua_State *L, const char *str);
161 LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name);
164 ** Garbage-collection functions
166 LUA_API int lua_getgcthreshold (lua_State *L);
167 LUA_API int lua_getgccount (lua_State *L);
168 LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold);
171 ** miscellaneous functions
173 LUA_API int lua_newtag (lua_State *L);
174 LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
175 LUA_API void lua_settag (lua_State *L, int tag);
177 LUA_API void lua_error (lua_State *L, const char *s);
179 LUA_API void lua_unref (lua_State *L, int ref);
181 LUA_API int lua_next (lua_State *L, int index);
182 LUA_API int lua_getn (lua_State *L, int index);
184 LUA_API void lua_concat (lua_State *L, int n);
186 LUA_API void *lua_newuserdata (lua_State *L, size_t size);
190 ** ===============================================================
191 ** some useful macros
192 ** ===============================================================
195 #define lua_pop(L,n) lua_settop(L, -(n)-1)
197 #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
198 #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0)
199 #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
200 #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t))
202 #define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)
203 #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE)
204 #define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA)
205 #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
206 #define lua_isnull(L,n) (lua_type(L,n) == LUA_TNONE)
208 #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY)
210 #endif
214 /******************************************************************************
215 * Copyright (C) 1994-2000 TeCGraf, PUC-Rio. All rights reserved.
217 * Permission is hereby granted, without written agreement and without license
218 * or royalty fees, to use, copy, modify, and distribute this software and its
219 * documentation for any purpose, including commercial applications, subject to
220 * the following conditions:
222 * - The above copyright notice and this permission notice shall appear in all
223 * copies or substantial portions of this software.
225 * - The origin of this software must not be misrepresented; you must not
226 * claim that you wrote the original software. If you use this software in a
227 * product, an acknowledgment in the product documentation would be greatly
228 * appreciated (but it is not required).
230 * - Altered source versions must be plainly marked as such, and must not be
231 * misrepresented as being the original software.
233 * The authors specifically disclaim any warranties, including, but not limited
234 * to, the implied warranties of merchantability and fitness for a particular
235 * purpose. The software provided hereunder is on an "as is" basis, and the
236 * authors have no obligation to provide maintenance, support, updates,
237 * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
238 * authors be held liable to any party for direct, indirect, special,
239 * incidental, or consequential damages arising out of the use of this software
240 * and its documentation.
242 * The Lua language and this implementation have been entirely designed and
243 * written by Waldemar Celes Filho, Roberto Ierusalimschy and
244 * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
246 * This implementation contains no third-party code.
247 ******************************************************************************/