Imported from ../lua-3.1.tar.gz.
[lua.git] / include / lua.h
blobbce5a2c7f8d6f898743724ace7d278b5d1854485
1 /*
2 ** $Id: lua.h,v 1.23 1998/06/18 16:51:53 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.1"
15 #define LUA_COPYRIGHT "Copyright (C) 1994-1998 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 void (*lua_CFunction) (void);
24 typedef unsigned int lua_Object;
26 typedef struct lua_State lua_State;
27 extern lua_State *lua_state;
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);
35 lua_Object lua_seterrormethod (void); /* In: new method */
37 int lua_newtag (void);
38 int lua_copytagmethods (int tagto, int tagfrom);
39 void lua_settag (int tag); /* In: object */
41 void lua_error (char *s);
42 int lua_dofile (char *filename); /* Out: returns */
43 int lua_dostring (char *string); /* Out: returns */
44 int lua_dobuffer (char *buff, int size, char *name);
45 /* Out: returns */
46 int lua_callfunction (lua_Object f);
47 /* In: parameters; Out: returns */
49 void lua_beginblock (void);
50 void lua_endblock (void);
52 lua_Object lua_lua2C (int number);
53 #define lua_getparam(_) lua_lua2C(_)
54 #define lua_getresult(_) lua_lua2C(_)
56 int lua_isnil (lua_Object object);
57 int lua_istable (lua_Object object);
58 int lua_isuserdata (lua_Object object);
59 int lua_iscfunction (lua_Object object);
60 int lua_isnumber (lua_Object object);
61 int lua_isstring (lua_Object object);
62 int lua_isfunction (lua_Object object);
64 double lua_getnumber (lua_Object object);
65 char *lua_getstring (lua_Object object);
66 long lua_strlen (lua_Object object);
67 lua_CFunction lua_getcfunction (lua_Object object);
68 void *lua_getuserdata (lua_Object object);
71 void lua_pushnil (void);
72 void lua_pushnumber (double n);
73 void lua_pushlstring (char *s, long len);
74 void lua_pushstring (char *s);
75 void lua_pushcclosure (lua_CFunction fn, int n);
76 void lua_pushusertag (void *u, int tag);
77 void lua_pushobject (lua_Object object);
79 lua_Object lua_pop (void);
81 lua_Object lua_getglobal (char *name);
82 lua_Object lua_rawgetglobal (char *name);
83 void lua_setglobal (char *name); /* In: value */
84 void lua_rawsetglobal (char *name); /* In: value */
86 void lua_settable (void); /* In: table, index, value */
87 void lua_rawsettable (void); /* In: table, index, value */
88 lua_Object lua_gettable (void); /* In: table, index */
89 lua_Object lua_rawgettable (void); /* In: table, index */
91 int lua_tag (lua_Object object);
94 int lua_ref (int lock); /* In: value */
95 lua_Object lua_getref (int ref);
96 void lua_unref (int ref);
98 lua_Object lua_createtable (void);
100 long lua_collectgarbage (long limit);
103 /* =============================================================== */
104 /* some useful macros/derived functions */
106 int (lua_call) (char *name);
107 #define lua_call(name) lua_callfunction(lua_getglobal(name))
109 void (lua_pushref) (int ref);
110 #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
112 int (lua_refobject) (lua_Object o, int l);
113 #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
115 void (lua_register) (char *n, lua_CFunction f);
116 #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
118 void (lua_pushuserdata) (void *u);
119 #define lua_pushuserdata(u) lua_pushusertag(u, 0)
121 void (lua_pushcfunction) (lua_CFunction f);
122 #define lua_pushcfunction(f) lua_pushcclosure(f, 0)
124 int (lua_clonetag) (int t);
125 #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
128 /* ==========================================================================
129 ** for compatibility with old versions. Avoid using these macros/functions
130 ** If your program does need any of these, define LUA_COMPAT2_5
134 #ifdef LUA_COMPAT2_5
137 lua_Object lua_setfallback (char *event, lua_CFunction fallback);
139 #define lua_storeglobal lua_setglobal
140 #define lua_type lua_tag
142 #define lua_lockobject(o) lua_refobject(o,1)
143 #define lua_lock() lua_ref(1)
144 #define lua_getlocked lua_getref
145 #define lua_pushlocked lua_pushref
146 #define lua_unlock lua_unref
148 #define lua_pushliteral(o) lua_pushstring(o)
150 #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
151 #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
153 #define lua_copystring(o) (strdup(lua_getstring(o)))
155 #define lua_getsubscript lua_gettable
156 #define lua_storesubscript lua_settable
158 #endif
160 #endif
164 /******************************************************************************
165 * Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
167 * Permission is hereby granted, without written agreement and without license
168 * or royalty fees, to use, copy, modify, and distribute this software and its
169 * documentation for any purpose, including commercial applications, subject to
170 * the following conditions:
172 * - The above copyright notice and this permission notice shall appear in all
173 * copies or substantial portions of this software.
175 * - The origin of this software must not be misrepresented; you must not
176 * claim that you wrote the original software. If you use this software in a
177 * product, an acknowledgment in the product documentation would be greatly
178 * appreciated (but it is not required).
180 * - Altered source versions must be plainly marked as such, and must not be
181 * misrepresented as being the original software.
183 * The authors specifically disclaim any warranties, including, but not limited
184 * to, the implied warranties of merchantability and fitness for a particular
185 * purpose. The software provided hereunder is on an "as is" basis, and the
186 * authors have no obligation to provide maintenance, support, updates,
187 * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
188 * authors be held liable to any party for direct, indirect, special,
189 * incidental, or consequential damages arising out of the use of this software
190 * and its documentation.
192 * The Lua language and this implementation have been entirely designed and
193 * written by Waldemar Celes Filho, Roberto Ierusalimschy and
194 * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
195 * This implementation contains no third-party code.
196 ******************************************************************************/