Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ceguilua/src/lua-5.0.3/lua/lua.h @ 1803

Last change on this file since 1803 was 1803, checked in by rgrieder, 16 years ago

added files for lua 5.1.3, lua 5.0.3, CEGUILua-0.6.1 and CEGUILua-0.5.0b

  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
1/*
2** $Id: lua.h,v 1.175c 2003/03/18 12:31:39 roberto Exp $
3** Lua - An Extensible Extension Language
4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5** http://www.lua.org   mailto:info@lua.org
6** See Copyright Notice at the end of this file
7*/
8
9
10#ifndef lua_h
11#define lua_h
12
13#include <stdarg.h>
14#include <stddef.h>
15
16
17#define LUA_VERSION     "Lua 5.0.3"
18#define LUA_COPYRIGHT   "Copyright (C) 1994-2006 Tecgraf, PUC-Rio"
19#define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
20
21
22
23/* option for multiple returns in `lua_pcall' and `lua_call' */
24#define LUA_MULTRET     (-1)
25
26
27/*
28** pseudo-indices
29*/
30#define LUA_REGISTRYINDEX       (-10000)
31#define LUA_GLOBALSINDEX        (-10001)
32#define lua_upvalueindex(i)     (LUA_GLOBALSINDEX-(i))
33
34
35/* error codes for `lua_load' and `lua_pcall' */
36#define LUA_ERRRUN      1
37#define LUA_ERRFILE     2
38#define LUA_ERRSYNTAX   3
39#define LUA_ERRMEM      4
40#define LUA_ERRERR      5
41
42
43typedef struct lua_State lua_State;
44
45typedef int (*lua_CFunction) (lua_State *L);
46
47
48/*
49** functions that read/write blocks when loading/dumping Lua chunks
50*/
51typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t *sz);
52
53typedef int (*lua_Chunkwriter) (lua_State *L, const void* p,
54                                size_t sz, void* ud);
55
56
57/*
58** basic types
59*/
60#define LUA_TNONE       (-1)
61
62#define LUA_TNIL        0
63#define LUA_TBOOLEAN    1
64#define LUA_TLIGHTUSERDATA      2
65#define LUA_TNUMBER     3
66#define LUA_TSTRING     4
67#define LUA_TTABLE      5
68#define LUA_TFUNCTION   6
69#define LUA_TUSERDATA   7
70#define LUA_TTHREAD     8
71
72
73/* minimum Lua stack available to a C function */
74#define LUA_MINSTACK    20
75
76
77/*
78** generic extra include file
79*/
80#ifdef LUA_USER_H
81#include LUA_USER_H
82#endif
83
84
85/* type of numbers in Lua */
86#ifndef LUA_NUMBER
87typedef double lua_Number;
88#else
89typedef LUA_NUMBER lua_Number;
90#endif
91
92
93/* mark for all API functions */
94#ifndef LUA_API
95#define LUA_API         extern
96#endif
97
98
99/*
100** state manipulation
101*/
102LUA_API lua_State *lua_open (void);
103LUA_API void       lua_close (lua_State *L);
104LUA_API lua_State *lua_newthread (lua_State *L);
105
106LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
107
108
109/*
110** basic stack manipulation
111*/
112LUA_API int   lua_gettop (lua_State *L);
113LUA_API void  lua_settop (lua_State *L, int idx);
114LUA_API void  lua_pushvalue (lua_State *L, int idx);
115LUA_API void  lua_remove (lua_State *L, int idx);
116LUA_API void  lua_insert (lua_State *L, int idx);
117LUA_API void  lua_replace (lua_State *L, int idx);
118LUA_API int   lua_checkstack (lua_State *L, int sz);
119
120LUA_API void  lua_xmove (lua_State *from, lua_State *to, int n);
121
122
123/*
124** access functions (stack -> C)
125*/
126
127LUA_API int             lua_isnumber (lua_State *L, int idx);
128LUA_API int             lua_isstring (lua_State *L, int idx);
129LUA_API int             lua_iscfunction (lua_State *L, int idx);
130LUA_API int             lua_isuserdata (lua_State *L, int idx);
131LUA_API int             lua_type (lua_State *L, int idx);
132LUA_API const char     *lua_typename (lua_State *L, int tp);
133
134LUA_API int            lua_equal (lua_State *L, int idx1, int idx2);
135LUA_API int            lua_rawequal (lua_State *L, int idx1, int idx2);
136LUA_API int            lua_lessthan (lua_State *L, int idx1, int idx2);
137
138LUA_API lua_Number      lua_tonumber (lua_State *L, int idx);
139LUA_API int             lua_toboolean (lua_State *L, int idx);
140LUA_API const char     *lua_tostring (lua_State *L, int idx);
141LUA_API size_t          lua_strlen (lua_State *L, int idx);
142LUA_API lua_CFunction   lua_tocfunction (lua_State *L, int idx);
143LUA_API void           *lua_touserdata (lua_State *L, int idx);
144LUA_API lua_State      *lua_tothread (lua_State *L, int idx);
145LUA_API const void     *lua_topointer (lua_State *L, int idx);
146
147
148/*
149** push functions (C -> stack)
150*/
151LUA_API void  lua_pushnil (lua_State *L);
152LUA_API void  lua_pushnumber (lua_State *L, lua_Number n);
153LUA_API void  lua_pushlstring (lua_State *L, const char *s, size_t l);
154LUA_API void  lua_pushstring (lua_State *L, const char *s);
155LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
156                                                    va_list argp);
157LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
158LUA_API void  lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
159LUA_API void  lua_pushboolean (lua_State *L, int b);
160LUA_API void  lua_pushlightuserdata (lua_State *L, void *p);
161
162
163/*
164** get functions (Lua -> stack)
165*/
166LUA_API void  lua_gettable (lua_State *L, int idx);
167LUA_API void  lua_rawget (lua_State *L, int idx);
168LUA_API void  lua_rawgeti (lua_State *L, int idx, int n);
169LUA_API void  lua_newtable (lua_State *L);
170LUA_API void *lua_newuserdata (lua_State *L, size_t sz);
171LUA_API int   lua_getmetatable (lua_State *L, int objindex);
172LUA_API void  lua_getfenv (lua_State *L, int idx);
173
174
175/*
176** set functions (stack -> Lua)
177*/
178LUA_API void  lua_settable (lua_State *L, int idx);
179LUA_API void  lua_rawset (lua_State *L, int idx);
180LUA_API void  lua_rawseti (lua_State *L, int idx, int n);
181LUA_API int   lua_setmetatable (lua_State *L, int objindex);
182LUA_API int   lua_setfenv (lua_State *L, int idx);
183
184
185/*
186** `load' and `call' functions (load and run Lua code)
187*/
188LUA_API void  lua_call (lua_State *L, int nargs, int nresults);
189LUA_API int   lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
190LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
191LUA_API int   lua_load (lua_State *L, lua_Chunkreader reader, void *dt,
192                        const char *chunkname);
193
194LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data);
195
196
197/*
198** coroutine functions
199*/
200LUA_API int  lua_yield (lua_State *L, int nresults);
201LUA_API int  lua_resume (lua_State *L, int narg);
202
203/*
204** garbage-collection functions
205*/
206LUA_API int   lua_getgcthreshold (lua_State *L);
207LUA_API int   lua_getgccount (lua_State *L);
208LUA_API void  lua_setgcthreshold (lua_State *L, int newthreshold);
209
210/*
211** miscellaneous functions
212*/
213
214LUA_API const char *lua_version (void);
215
216LUA_API int   lua_error (lua_State *L);
217
218LUA_API int   lua_next (lua_State *L, int idx);
219
220LUA_API void  lua_concat (lua_State *L, int n);
221
222
223
224/*
225** ===============================================================
226** some useful macros
227** ===============================================================
228*/
229
230#define lua_boxpointer(L,u) \
231        (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))
232
233#define lua_unboxpointer(L,i)   (*(void **)(lua_touserdata(L, i)))
234
235#define lua_pop(L,n)            lua_settop(L, -(n)-1)
236
237#define lua_register(L,n,f) \
238        (lua_pushstring(L, n), \
239         lua_pushcfunction(L, f), \
240         lua_settable(L, LUA_GLOBALSINDEX))
241
242#define lua_pushcfunction(L,f)  lua_pushcclosure(L, f, 0)
243
244#define lua_isfunction(L,n)     (lua_type(L,n) == LUA_TFUNCTION)
245#define lua_istable(L,n)        (lua_type(L,n) == LUA_TTABLE)
246#define lua_islightuserdata(L,n)        (lua_type(L,n) == LUA_TLIGHTUSERDATA)
247#define lua_isnil(L,n)          (lua_type(L,n) == LUA_TNIL)
248#define lua_isboolean(L,n)      (lua_type(L,n) == LUA_TBOOLEAN)
249#define lua_isnone(L,n)         (lua_type(L,n) == LUA_TNONE)
250#define lua_isnoneornil(L, n)   (lua_type(L,n) <= 0)
251
252#define lua_pushliteral(L, s)   \
253        lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
254
255
256
257/*
258** compatibility macros and functions
259*/
260
261
262LUA_API int lua_pushupvalues (lua_State *L);
263
264#define lua_getregistry(L)      lua_pushvalue(L, LUA_REGISTRYINDEX)
265#define lua_setglobal(L,s)      \
266   (lua_pushstring(L, s), lua_insert(L, -2), lua_settable(L, LUA_GLOBALSINDEX))
267
268#define lua_getglobal(L,s)      \
269                (lua_pushstring(L, s), lua_gettable(L, LUA_GLOBALSINDEX))
270
271
272/* compatibility with ref system */
273
274/* pre-defined references */
275#define LUA_NOREF       (-2)
276#define LUA_REFNIL      (-1)
277
278#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
279      (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
280
281#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))
282
283#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, ref)
284
285
286
287/*
288** {======================================================================
289** useful definitions for Lua kernel and libraries
290** =======================================================================
291*/
292
293/* formats for Lua numbers */
294#ifndef LUA_NUMBER_SCAN
295#define LUA_NUMBER_SCAN         "%lf"
296#endif
297
298#ifndef LUA_NUMBER_FMT
299#define LUA_NUMBER_FMT          "%.14g"
300#endif
301
302/* }====================================================================== */
303
304
305/*
306** {======================================================================
307** Debug API
308** =======================================================================
309*/
310
311
312/*
313** Event codes
314*/
315#define LUA_HOOKCALL    0
316#define LUA_HOOKRET     1
317#define LUA_HOOKLINE    2
318#define LUA_HOOKCOUNT   3
319#define LUA_HOOKTAILRET 4
320
321
322/*
323** Event masks
324*/
325#define LUA_MASKCALL    (1 << LUA_HOOKCALL)
326#define LUA_MASKRET     (1 << LUA_HOOKRET)
327#define LUA_MASKLINE    (1 << LUA_HOOKLINE)
328#define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)
329
330typedef struct lua_Debug lua_Debug;  /* activation record */
331
332typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
333
334
335LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
336LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
337LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
338LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
339LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
340LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
341
342LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
343LUA_API lua_Hook lua_gethook (lua_State *L);
344LUA_API int lua_gethookmask (lua_State *L);
345LUA_API int lua_gethookcount (lua_State *L);
346
347
348#define LUA_IDSIZE      60
349
350struct lua_Debug {
351  int event;
352  const char *name;     /* (n) */
353  const char *namewhat; /* (n) `global', `local', `field', `method' */
354  const char *what;     /* (S) `Lua', `C', `main', `tail' */
355  const char *source;   /* (S) */
356  int currentline;      /* (l) */
357  int nups;             /* (u) number of upvalues */
358  int linedefined;      /* (S) */
359  char short_src[LUA_IDSIZE]; /* (S) */
360  /* private part */
361  int i_ci;  /* active function */
362};
363
364/* }====================================================================== */
365
366
367/******************************************************************************
368* Copyright (C) 1994-2006 Tecgraf, PUC-Rio.  All rights reserved.
369*
370* Permission is hereby granted, free of charge, to any person obtaining
371* a copy of this software and associated documentation files (the
372* "Software"), to deal in the Software without restriction, including
373* without limitation the rights to use, copy, modify, merge, publish,
374* distribute, sublicense, and/or sell copies of the Software, and to
375* permit persons to whom the Software is furnished to do so, subject to
376* the following conditions:
377*
378* The above copyright notice and this permission notice shall be
379* included in all copies or substantial portions of the Software.
380*
381* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
382* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
383* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
384* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
385* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
386* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
387* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
388******************************************************************************/
389
390
391#endif
Note: See TracBrowser for help on using the repository browser.