lua/lua.h

265 lines
11 KiB
C
Raw Normal View History

1993-07-28 17:18:00 +04:00
/*
** $Id: lua.h,v 1.51 2000/05/09 14:50:16 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
1997-12-09 16:50:08 +03:00
** www: http://www.tecgraf.puc-rio.br/lua/
1998-06-07 01:05:52 +04:00
** See Copyright Notice at the end of this file
1993-07-28 17:18:00 +04:00
*/
#ifndef lua_h
#define lua_h
2000-04-17 23:23:12 +04:00
#define LUA_VERSION "Lua 4.0 (alpha)"
1999-12-30 21:29:46 +03:00
#define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
1995-10-31 20:05:35 +03:00
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
2000-05-09 18:50:16 +04:00
#define LUA_ALERT "_ALERT"
#define LUA_ERRORMESSAGE "_ERRORMESSAGE"
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
#define LUA_ANYTAG (-1)
typedef struct lua_State lua_State;
2000-04-14 21:46:37 +04:00
typedef void (*lua_CFunction) (lua_State *L);
typedef struct lua_TObject *lua_Object;
#define LUA_NOOBJECT ((lua_Object)0)
1998-12-15 17:59:43 +03:00
lua_State *lua_newstate (const char *s, ...);
void lua_close (lua_State *L);
lua_Object lua_settagmethod (lua_State *L, int tag, const char *event);
1999-08-17 00:52:00 +04:00
/* In: new method */
lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event);
int lua_newtag (lua_State *L);
int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
void lua_settag (lua_State *L, int tag); /* In: object */
1994-11-07 21:27:39 +03:00
void lua_error (lua_State *L, const char *s);
int lua_dofile (lua_State *L, const char *filename);
1999-08-17 00:52:00 +04:00
/* Out: returns */
int lua_dostring (lua_State *L, const char *str);
1999-08-17 00:52:00 +04:00
/* Out: returns */
int lua_dobuffer (lua_State *L, const char *buff, int size,
1999-08-17 00:52:00 +04:00
const char *name); /* Out: returns */
int lua_callfunction (lua_State *L, lua_Object f);
/* In: parameters; Out: returns */
1993-07-28 17:18:00 +04:00
void lua_beginblock (lua_State *L);
void lua_endblock (lua_State *L);
void lua_pushglobaltable (lua_State *L);
void lua_setglobaltable (lua_State *L, lua_Object newtable);
lua_Object lua_lua2C (lua_State *L, int number);
#define lua_getparam lua_lua2C
#define lua_getresult lua_lua2C
1994-11-07 19:34:44 +03:00
const char *lua_type (lua_State *L, lua_Object obj);
1999-10-07 23:04:30 +04:00
int lua_isnil (lua_State *L, lua_Object obj);
int lua_istable (lua_State *L, lua_Object obj);
int lua_isuserdata (lua_State *L, lua_Object obj);
int lua_iscfunction (lua_State *L, lua_Object obj);
int lua_isnumber (lua_State *L, lua_Object obj);
int lua_isstring (lua_State *L, lua_Object obj);
int lua_isfunction (lua_State *L, lua_Object obj);
int lua_equal (lua_State *L, lua_Object o1, lua_Object o2);
1999-11-11 20:02:40 +03:00
double lua_getnumber (lua_State *L, lua_Object obj);
const char *lua_getstring (lua_State *L, lua_Object obj);
long lua_strlen (lua_State *L, lua_Object obj);
lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj);
void *lua_getuserdata (lua_State *L, lua_Object obj);
1997-06-19 01:20:45 +04:00
1993-07-28 17:18:00 +04:00
void lua_pushnil (lua_State *L);
void lua_pushnumber (lua_State *L, double n);
void lua_pushlstring (lua_State *L, const char *s, long len);
void lua_pushstring (lua_State *L, const char *s);
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
void lua_pushusertag (lua_State *L, void *u, int tag);
void lua_pushobject (lua_State *L, lua_Object obj);
1993-07-28 17:18:00 +04:00
lua_Object lua_pop (lua_State *L);
lua_Object lua_getglobal (lua_State *L, const char *name);
void lua_setglobal (lua_State *L, const char *name); /* In: value */
lua_Object lua_rawgetglobal (lua_State *L, const char *name);
void lua_rawsetglobal (lua_State *L, const char *name);/* In: value */
1994-11-07 19:34:44 +03:00
void lua_settable (lua_State *L); /* In: table, index, value */
void lua_rawsettable (lua_State *L); /* In: table, index, value */
lua_Object lua_gettable (lua_State *L); /* In: table, index */
lua_Object lua_rawgettable (lua_State *L); /* In: table, index */
1993-07-28 17:18:00 +04:00
int lua_tag (lua_State *L, lua_Object obj);
1993-07-28 17:18:00 +04:00
int lua_next (lua_State *L, lua_Object o, int i);
/* Out: ref, value */
int lua_ref (lua_State *L, int lock); /* In: value */
lua_Object lua_getref (lua_State *L, int ref);
void lua_unref (lua_State *L, int ref);
1994-11-08 22:56:39 +03:00
lua_Object lua_createtable (lua_State *L);
long lua_collectgarbage (lua_State *L, long limit);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#ifdef LUA_REENTRANT
1994-11-07 19:34:44 +03:00
#define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name))
#define lua_pushref(L,ref) lua_pushobject(L, lua_getref(L, ref))
#define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l))
#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
#define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0)
#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
#define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t))
#else
1994-11-18 00:23:43 +03:00
#define lua_call(name) lua_callfunction(lua_getglobal(name))
#define lua_pushref(ref) lua_pushobject(lua_getref(ref))
#define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
#define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
#define lua_pushuserdata(u) lua_pushusertag(u, 0)
#define lua_pushcfunction(f) lua_pushcclosure(f, 0)
#define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
1997-06-19 01:20:45 +04:00
#endif
#ifndef LUA_REENTRANT
/*
** ===============================================================
** Macros for single-state use
** ===============================================================
*/
1994-12-13 18:54:21 +03:00
extern lua_State *lua_state;
1994-12-13 18:54:21 +03:00
2000-04-14 21:46:37 +04:00
#define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0))))
#define lua_close() (lua_close)(lua_state)
#define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event)
#define lua_gettagmethod(tag,event) (lua_gettagmethod)(lua_state, tag,event)
#define lua_newtag() (lua_newtag)(lua_state)
#define lua_copytagmethods(tagto,tagfrom) \
(lua_copytagmethods)(lua_state, tagto,tagfrom)
#define lua_settag(tag) (lua_settag)(lua_state, tag)
#define lua_error(s) (lua_error)(lua_state, s)
#define lua_dofile(filename) (lua_dofile)(lua_state, filename)
#define lua_dostring(str) (lua_dostring)(lua_state, str)
#define lua_dobuffer(b,s,n) (lua_dobuffer)(lua_state, b,s,n)
#define lua_callfunction(f) (lua_callfunction)(lua_state, f)
#define lua_beginblock() (lua_beginblock)(lua_state)
#define lua_endblock() (lua_endblock)(lua_state)
#define lua_pushglobaltable() (lua_pushglobaltable)(lua_state)
#define lua_setglobaltable(t) (lua_setglobaltable)(lua_state, t)
#define lua_lua2C(number) (lua_lua2C)(lua_state, number)
#define lua_type(obj) (lua_type)(lua_state, obj)
#define lua_isnil(obj) (lua_isnil)(lua_state, obj)
#define lua_istable(obj) (lua_istable)(lua_state, obj)
#define lua_isuserdata(obj) (lua_isuserdata)(lua_state, obj)
#define lua_iscfunction(obj) (lua_iscfunction)(lua_state, obj)
#define lua_isnumber(obj) (lua_isnumber)(lua_state, obj)
#define lua_isstring(obj) (lua_isstring)(lua_state, obj)
#define lua_isfunction(obj) (lua_isfunction)(lua_state, obj)
#define lua_equal(o1,o2) (lua_equal)(lua_state, o1,o2)
#define lua_getnumber(obj) (lua_getnumber)(lua_state, obj)
#define lua_getstring(obj) (lua_getstring)(lua_state, obj)
#define lua_strlen(obj) (lua_strlen)(lua_state, obj)
#define lua_getcfunction(obj) (lua_getcfunction)(lua_state, obj)
#define lua_getuserdata(obj) (lua_getuserdata)(lua_state, obj)
#define lua_pushnil() (lua_pushnil)(lua_state)
#define lua_pushnumber(n) (lua_pushnumber)(lua_state, n)
#define lua_pushlstring(s,len) (lua_pushlstring)(lua_state, s,len)
#define lua_pushstring(s) (lua_pushstring)(lua_state, s)
#define lua_pushusertag(u,tag) (lua_pushusertag)(lua_state, u,tag)
#define lua_pushobject(obj) (lua_pushobject)(lua_state, obj)
#define lua_pop() (lua_pop)(lua_state)
#define lua_getglobal(name) (lua_getglobal)(lua_state, name)
#define lua_setglobal(name) (lua_setglobal)(lua_state, name)
#define lua_rawgetglobal(name) (lua_rawgetglobal)(lua_state, name)
#define lua_rawsetglobal(name) (lua_rawsetglobal)(lua_state, name)
#define lua_settable() (lua_settable)(lua_state)
#define lua_rawsettable() (lua_rawsettable)(lua_state)
#define lua_gettable() (lua_gettable)(lua_state)
#define lua_rawgettable() (lua_rawgettable)(lua_state)
#define lua_tag(obj) (lua_tag)(lua_state, obj)
#define lua_next(o,i) (lua_next)(lua_state, o,i)
#define lua_ref(lock) (lua_ref)(lua_state, lock)
#define lua_getref(ref) (lua_getref)(lua_state, ref)
#define lua_unref(ref) (lua_unref)(lua_state, ref)
#define lua_createtable() (lua_createtable)(lua_state)
#define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit)
2000-04-14 21:46:37 +04:00
/*
2000-04-17 23:23:12 +04:00
** the following typecast is a little dirty, but we know of no other
2000-04-14 21:46:37 +04:00
** way to keep compatibility with old definition of `lua_CFunction'
*/
#define lua_pushcclosure(fn,n) \
(lua_pushcclosure)(lua_state, (lua_CFunction)(fn), n)
1993-07-28 17:18:00 +04:00
#endif
1997-06-19 01:20:45 +04:00
1997-06-19 01:20:45 +04:00
#endif
1998-06-07 01:05:52 +04:00
2000-04-14 21:46:37 +04:00
1998-06-07 01:05:52 +04:00
/******************************************************************************
1999-12-30 21:29:46 +03:00
* Copyright (C) 1994-2000 TeCGraf, PUC-Rio. All rights reserved.
1998-06-07 01:05:52 +04:00
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, including commercial applications, subject to
* the following conditions:
*
* - The above copyright notice and this permission notice shall appear in all
* copies or substantial portions of this software.
*
* - The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be greatly
* appreciated (but it is not required).
*
* - Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* The authors specifically disclaim any warranties, including, but not limited
* to, the implied warranties of merchantability and fitness for a particular
* purpose. The software provided hereunder is on an "as is" basis, and the
* authors have no obligation to provide maintenance, support, updates,
* enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
* authors be held liable to any party for direct, indirect, special,
* incidental, or consequential damages arising out of the use of this software
* and its documentation.
*
* The Lua language and this implementation have been entirely designed and
* written by Waldemar Celes Filho, Roberto Ierusalimschy and
* Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
1999-02-26 00:07:26 +03:00
*
1998-06-07 01:05:52 +04:00
* This implementation contains no third-party code.
******************************************************************************/