Imported from ../lua-3.2.tar.gz.
[lua.git] / include / lua.h
blobf46b2e1d6b0e2048d69317dd53457b5b231a5b2e
1 /*
2 ** $Id: lua.h,v 1.32 1999/05/11 20:29:19 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
14 #define LUA_VERSION "Lua 3.2"
15 #define LUA_COPYRIGHT "Copyright (C) 1994-1999 TeCGraf, PUC-Rio"
16 #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
19 #define LUA_NOOBJECT 0
21 #define LUA_ANYTAG (-1)
23 typedef struct lua_State lua_State;
24 extern lua_State *lua_state;
26 typedef void (*lua_CFunction) (void);
27 typedef unsigned int lua_Object;
29 void lua_open (void);
30 void lua_close (void);
31 lua_State *lua_setstate (lua_State *st);
33 lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
34 lua_Object lua_gettagmethod (int tag, char *event);
36 int lua_newtag (void);
37 int lua_copytagmethods (int tagto, int tagfrom);
38 void lua_settag (int tag); /* In: object */
40 void lua_error (char *s);
41 int lua_dofile (char *filename); /* Out: returns */
42 int lua_dostring (char *string); /* Out: returns */
43 int lua_dobuffer (char *buff, int size, char *name);
44 /* Out: returns */
45 int lua_callfunction (lua_Object f);
46 /* In: parameters; Out: returns */
48 void lua_beginblock (void);
49 void lua_endblock (void);
51 lua_Object lua_lua2C (int number);
52 #define lua_getparam(_) lua_lua2C(_)
53 #define lua_getresult(_) lua_lua2C(_)
55 int lua_isnil (lua_Object object);
56 int lua_istable (lua_Object object);
57 int lua_isuserdata (lua_Object object);
58 int lua_iscfunction (lua_Object object);
59 int lua_isnumber (lua_Object object);
60 int lua_isstring (lua_Object object);
61 int lua_isfunction (lua_Object object);
63 double lua_getnumber (lua_Object object);
64 char *lua_getstring (lua_Object object);
65 long lua_strlen (lua_Object object);
66 lua_CFunction lua_getcfunction (lua_Object object);
67 void *lua_getuserdata (lua_Object object);
70 void lua_pushnil (void);
71 void lua_pushnumber (double n);
72 void lua_pushlstring (char *s, long len);
73 void lua_pushstring (char *s);
74 void lua_pushcclosure (lua_CFunction fn, int n);
75 void lua_pushusertag (void *u, int tag);
76 void lua_pushobject (lua_Object object);
78 lua_Object lua_pop (void);
80 lua_Object lua_getglobal (char *name);
81 lua_Object lua_rawgetglobal (char *name);
82 void lua_setglobal (char *name); /* In: value */
83 void lua_rawsetglobal (char *name); /* In: value */
85 void lua_settable (void); /* In: table, index, value */
86 void lua_rawsettable (void); /* In: table, index, value */
87 lua_Object lua_gettable (void); /* In: table, index */
88 lua_Object lua_rawgettable (void); /* In: table, index */
90 int lua_tag (lua_Object object);
92 char *lua_nextvar (char *varname); /* Out: value */
93 int lua_next (lua_Object o, int i);
94 /* Out: ref, value */
96 int lua_ref (int lock); /* In: value */
97 lua_Object lua_getref (int ref);
98 void lua_unref (int ref);
100 lua_Object lua_createtable (void);
102 long lua_collectgarbage (long limit);
105 /* =============================================================== */
106 /* some useful macros/functions */
108 #define lua_call(name) lua_callfunction(lua_getglobal(name))
110 #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
112 #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
114 #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
116 #define lua_pushuserdata(u) lua_pushusertag(u, 0)
118 #define lua_pushcfunction(f) lua_pushcclosure(f, 0)
120 #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
122 lua_Object lua_seterrormethod (void); /* In: new method */
124 /* ==========================================================================
125 ** for compatibility with old versions. Avoid using these macros/functions
126 ** If your program does need any of these, define LUA_COMPAT2_5
130 #ifdef LUA_COMPAT2_5
133 lua_Object lua_setfallback (char *event, lua_CFunction fallback);
135 #define lua_storeglobal lua_setglobal
136 #define lua_type lua_tag
138 #define lua_lockobject(o) lua_refobject(o,1)
139 #define lua_lock() lua_ref(1)
140 #define lua_getlocked lua_getref
141 #define lua_pushlocked lua_pushref
142 #define lua_unlock lua_unref
144 #define lua_pushliteral(o) lua_pushstring(o)
146 #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
147 #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
149 #define lua_copystring(o) (strdup(lua_getstring(o)))
151 #define lua_getsubscript lua_gettable
152 #define lua_storesubscript lua_settable
154 #endif
156 #endif
160 /******************************************************************************
161 * Copyright (c) 1994-1999 TeCGraf, PUC-Rio. All rights reserved.
163 * Permission is hereby granted, without written agreement and without license
164 * or royalty fees, to use, copy, modify, and distribute this software and its
165 * documentation for any purpose, including commercial applications, subject to
166 * the following conditions:
168 * - The above copyright notice and this permission notice shall appear in all
169 * copies or substantial portions of this software.
171 * - The origin of this software must not be misrepresented; you must not
172 * claim that you wrote the original software. If you use this software in a
173 * product, an acknowledgment in the product documentation would be greatly
174 * appreciated (but it is not required).
176 * - Altered source versions must be plainly marked as such, and must not be
177 * misrepresented as being the original software.
179 * The authors specifically disclaim any warranties, including, but not limited
180 * to, the implied warranties of merchantability and fitness for a particular
181 * purpose. The software provided hereunder is on an "as is" basis, and the
182 * authors have no obligation to provide maintenance, support, updates,
183 * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
184 * authors be held liable to any party for direct, indirect, special,
185 * incidental, or consequential damages arising out of the use of this software
186 * and its documentation.
188 * The Lua language and this implementation have been entirely designed and
189 * written by Waldemar Celes Filho, Roberto Ierusalimschy and
190 * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
192 * This implementation contains no third-party code.
193 ******************************************************************************/