xref: /redis-3.2.3/deps/lua/src/lua.h (revision 214adc50)
121d3294cSantirez /*
2*214adc50Santirez ** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $
321d3294cSantirez ** Lua - An Extensible Extension Language
421d3294cSantirez ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
521d3294cSantirez ** See Copyright Notice at the end of this file
621d3294cSantirez */
721d3294cSantirez 
821d3294cSantirez 
921d3294cSantirez #ifndef lua_h
1021d3294cSantirez #define lua_h
1121d3294cSantirez 
1221d3294cSantirez #include <stdarg.h>
1321d3294cSantirez #include <stddef.h>
1421d3294cSantirez 
1521d3294cSantirez 
1621d3294cSantirez #include "luaconf.h"
1721d3294cSantirez 
1821d3294cSantirez 
1921d3294cSantirez #define LUA_VERSION	"Lua 5.1"
20*214adc50Santirez #define LUA_RELEASE	"Lua 5.1.5"
2121d3294cSantirez #define LUA_VERSION_NUM	501
22*214adc50Santirez #define LUA_COPYRIGHT	"Copyright (C) 1994-2012 Lua.org, PUC-Rio"
2321d3294cSantirez #define LUA_AUTHORS 	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2421d3294cSantirez 
2521d3294cSantirez 
2621d3294cSantirez /* mark for precompiled code (`<esc>Lua') */
2721d3294cSantirez #define	LUA_SIGNATURE	"\033Lua"
2821d3294cSantirez 
2921d3294cSantirez /* option for multiple returns in `lua_pcall' and `lua_call' */
3021d3294cSantirez #define LUA_MULTRET	(-1)
3121d3294cSantirez 
3221d3294cSantirez 
3321d3294cSantirez /*
3421d3294cSantirez ** pseudo-indices
3521d3294cSantirez */
3621d3294cSantirez #define LUA_REGISTRYINDEX	(-10000)
3721d3294cSantirez #define LUA_ENVIRONINDEX	(-10001)
3821d3294cSantirez #define LUA_GLOBALSINDEX	(-10002)
3921d3294cSantirez #define lua_upvalueindex(i)	(LUA_GLOBALSINDEX-(i))
4021d3294cSantirez 
4121d3294cSantirez 
4221d3294cSantirez /* thread status; 0 is OK */
4321d3294cSantirez #define LUA_YIELD	1
4421d3294cSantirez #define LUA_ERRRUN	2
4521d3294cSantirez #define LUA_ERRSYNTAX	3
4621d3294cSantirez #define LUA_ERRMEM	4
4721d3294cSantirez #define LUA_ERRERR	5
4821d3294cSantirez 
4921d3294cSantirez 
5021d3294cSantirez typedef struct lua_State lua_State;
5121d3294cSantirez 
5221d3294cSantirez typedef int (*lua_CFunction) (lua_State *L);
5321d3294cSantirez 
5421d3294cSantirez 
5521d3294cSantirez /*
5621d3294cSantirez ** functions that read/write blocks when loading/dumping Lua chunks
5721d3294cSantirez */
5821d3294cSantirez typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
5921d3294cSantirez 
6021d3294cSantirez typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
6121d3294cSantirez 
6221d3294cSantirez 
6321d3294cSantirez /*
6421d3294cSantirez ** prototype for memory-allocation functions
6521d3294cSantirez */
6621d3294cSantirez typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
6721d3294cSantirez 
6821d3294cSantirez 
6921d3294cSantirez /*
7021d3294cSantirez ** basic types
7121d3294cSantirez */
7221d3294cSantirez #define LUA_TNONE		(-1)
7321d3294cSantirez 
7421d3294cSantirez #define LUA_TNIL		0
7521d3294cSantirez #define LUA_TBOOLEAN		1
7621d3294cSantirez #define LUA_TLIGHTUSERDATA	2
7721d3294cSantirez #define LUA_TNUMBER		3
7821d3294cSantirez #define LUA_TSTRING		4
7921d3294cSantirez #define LUA_TTABLE		5
8021d3294cSantirez #define LUA_TFUNCTION		6
8121d3294cSantirez #define LUA_TUSERDATA		7
8221d3294cSantirez #define LUA_TTHREAD		8
8321d3294cSantirez 
8421d3294cSantirez 
8521d3294cSantirez 
8621d3294cSantirez /* minimum Lua stack available to a C function */
8721d3294cSantirez #define LUA_MINSTACK	20
8821d3294cSantirez 
8921d3294cSantirez 
9021d3294cSantirez /*
9121d3294cSantirez ** generic extra include file
9221d3294cSantirez */
9321d3294cSantirez #if defined(LUA_USER_H)
9421d3294cSantirez #include LUA_USER_H
9521d3294cSantirez #endif
9621d3294cSantirez 
9721d3294cSantirez 
9821d3294cSantirez /* type of numbers in Lua */
9921d3294cSantirez typedef LUA_NUMBER lua_Number;
10021d3294cSantirez 
10121d3294cSantirez 
10221d3294cSantirez /* type for integer functions */
10321d3294cSantirez typedef LUA_INTEGER lua_Integer;
10421d3294cSantirez 
10521d3294cSantirez 
10621d3294cSantirez 
10721d3294cSantirez /*
10821d3294cSantirez ** state manipulation
10921d3294cSantirez */
11021d3294cSantirez LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
11121d3294cSantirez LUA_API void       (lua_close) (lua_State *L);
11221d3294cSantirez LUA_API lua_State *(lua_newthread) (lua_State *L);
11321d3294cSantirez 
11421d3294cSantirez LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
11521d3294cSantirez 
11621d3294cSantirez 
11721d3294cSantirez /*
11821d3294cSantirez ** basic stack manipulation
11921d3294cSantirez */
12021d3294cSantirez LUA_API int   (lua_gettop) (lua_State *L);
12121d3294cSantirez LUA_API void  (lua_settop) (lua_State *L, int idx);
12221d3294cSantirez LUA_API void  (lua_pushvalue) (lua_State *L, int idx);
12321d3294cSantirez LUA_API void  (lua_remove) (lua_State *L, int idx);
12421d3294cSantirez LUA_API void  (lua_insert) (lua_State *L, int idx);
12521d3294cSantirez LUA_API void  (lua_replace) (lua_State *L, int idx);
12621d3294cSantirez LUA_API int   (lua_checkstack) (lua_State *L, int sz);
12721d3294cSantirez 
12821d3294cSantirez LUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);
12921d3294cSantirez 
13021d3294cSantirez 
13121d3294cSantirez /*
13221d3294cSantirez ** access functions (stack -> C)
13321d3294cSantirez */
13421d3294cSantirez 
13521d3294cSantirez LUA_API int             (lua_isnumber) (lua_State *L, int idx);
13621d3294cSantirez LUA_API int             (lua_isstring) (lua_State *L, int idx);
13721d3294cSantirez LUA_API int             (lua_iscfunction) (lua_State *L, int idx);
13821d3294cSantirez LUA_API int             (lua_isuserdata) (lua_State *L, int idx);
13921d3294cSantirez LUA_API int             (lua_type) (lua_State *L, int idx);
14021d3294cSantirez LUA_API const char     *(lua_typename) (lua_State *L, int tp);
14121d3294cSantirez 
14221d3294cSantirez LUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);
14321d3294cSantirez LUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);
14421d3294cSantirez LUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);
14521d3294cSantirez 
14621d3294cSantirez LUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);
14721d3294cSantirez LUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);
14821d3294cSantirez LUA_API int             (lua_toboolean) (lua_State *L, int idx);
14921d3294cSantirez LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
15021d3294cSantirez LUA_API size_t          (lua_objlen) (lua_State *L, int idx);
15121d3294cSantirez LUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);
15221d3294cSantirez LUA_API void	       *(lua_touserdata) (lua_State *L, int idx);
15321d3294cSantirez LUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);
15421d3294cSantirez LUA_API const void     *(lua_topointer) (lua_State *L, int idx);
15521d3294cSantirez 
15621d3294cSantirez 
15721d3294cSantirez /*
15821d3294cSantirez ** push functions (C -> stack)
15921d3294cSantirez */
16021d3294cSantirez LUA_API void  (lua_pushnil) (lua_State *L);
16121d3294cSantirez LUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);
16221d3294cSantirez LUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);
16321d3294cSantirez LUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);
16421d3294cSantirez LUA_API void  (lua_pushstring) (lua_State *L, const char *s);
16521d3294cSantirez LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
16621d3294cSantirez                                                       va_list argp);
16721d3294cSantirez LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
16821d3294cSantirez LUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
16921d3294cSantirez LUA_API void  (lua_pushboolean) (lua_State *L, int b);
17021d3294cSantirez LUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);
17121d3294cSantirez LUA_API int   (lua_pushthread) (lua_State *L);
17221d3294cSantirez 
17321d3294cSantirez 
17421d3294cSantirez /*
17521d3294cSantirez ** get functions (Lua -> stack)
17621d3294cSantirez */
17721d3294cSantirez LUA_API void  (lua_gettable) (lua_State *L, int idx);
17821d3294cSantirez LUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);
17921d3294cSantirez LUA_API void  (lua_rawget) (lua_State *L, int idx);
18021d3294cSantirez LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
18121d3294cSantirez LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
18221d3294cSantirez LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
18321d3294cSantirez LUA_API int   (lua_getmetatable) (lua_State *L, int objindex);
18421d3294cSantirez LUA_API void  (lua_getfenv) (lua_State *L, int idx);
18521d3294cSantirez 
18621d3294cSantirez 
18721d3294cSantirez /*
18821d3294cSantirez ** set functions (stack -> Lua)
18921d3294cSantirez */
19021d3294cSantirez LUA_API void  (lua_settable) (lua_State *L, int idx);
19121d3294cSantirez LUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);
19221d3294cSantirez LUA_API void  (lua_rawset) (lua_State *L, int idx);
19321d3294cSantirez LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
19421d3294cSantirez LUA_API int   (lua_setmetatable) (lua_State *L, int objindex);
19521d3294cSantirez LUA_API int   (lua_setfenv) (lua_State *L, int idx);
19621d3294cSantirez 
19721d3294cSantirez 
19821d3294cSantirez /*
19921d3294cSantirez ** `load' and `call' functions (load and run Lua code)
20021d3294cSantirez */
20121d3294cSantirez LUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);
20221d3294cSantirez LUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
20321d3294cSantirez LUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
20421d3294cSantirez LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
20521d3294cSantirez                                         const char *chunkname);
20621d3294cSantirez 
20721d3294cSantirez LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
20821d3294cSantirez 
20921d3294cSantirez 
21021d3294cSantirez /*
21121d3294cSantirez ** coroutine functions
21221d3294cSantirez */
21321d3294cSantirez LUA_API int  (lua_yield) (lua_State *L, int nresults);
21421d3294cSantirez LUA_API int  (lua_resume) (lua_State *L, int narg);
21521d3294cSantirez LUA_API int  (lua_status) (lua_State *L);
21621d3294cSantirez 
21721d3294cSantirez /*
21821d3294cSantirez ** garbage-collection function and options
21921d3294cSantirez */
22021d3294cSantirez 
22121d3294cSantirez #define LUA_GCSTOP		0
22221d3294cSantirez #define LUA_GCRESTART		1
22321d3294cSantirez #define LUA_GCCOLLECT		2
22421d3294cSantirez #define LUA_GCCOUNT		3
22521d3294cSantirez #define LUA_GCCOUNTB		4
22621d3294cSantirez #define LUA_GCSTEP		5
22721d3294cSantirez #define LUA_GCSETPAUSE		6
22821d3294cSantirez #define LUA_GCSETSTEPMUL	7
22921d3294cSantirez 
23021d3294cSantirez LUA_API int (lua_gc) (lua_State *L, int what, int data);
23121d3294cSantirez 
23221d3294cSantirez 
23321d3294cSantirez /*
23421d3294cSantirez ** miscellaneous functions
23521d3294cSantirez */
23621d3294cSantirez 
23721d3294cSantirez LUA_API int   (lua_error) (lua_State *L);
23821d3294cSantirez 
23921d3294cSantirez LUA_API int   (lua_next) (lua_State *L, int idx);
24021d3294cSantirez 
24121d3294cSantirez LUA_API void  (lua_concat) (lua_State *L, int n);
24221d3294cSantirez 
24321d3294cSantirez LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
24421d3294cSantirez LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
24521d3294cSantirez 
24621d3294cSantirez 
24721d3294cSantirez 
24821d3294cSantirez /*
24921d3294cSantirez ** ===============================================================
25021d3294cSantirez ** some useful macros
25121d3294cSantirez ** ===============================================================
25221d3294cSantirez */
25321d3294cSantirez 
25421d3294cSantirez #define lua_pop(L,n)		lua_settop(L, -(n)-1)
25521d3294cSantirez 
25621d3294cSantirez #define lua_newtable(L)		lua_createtable(L, 0, 0)
25721d3294cSantirez 
25821d3294cSantirez #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
25921d3294cSantirez 
26021d3294cSantirez #define lua_pushcfunction(L,f)	lua_pushcclosure(L, (f), 0)
26121d3294cSantirez 
26221d3294cSantirez #define lua_strlen(L,i)		lua_objlen(L, (i))
26321d3294cSantirez 
26421d3294cSantirez #define lua_isfunction(L,n)	(lua_type(L, (n)) == LUA_TFUNCTION)
26521d3294cSantirez #define lua_istable(L,n)	(lua_type(L, (n)) == LUA_TTABLE)
26621d3294cSantirez #define lua_islightuserdata(L,n)	(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
26721d3294cSantirez #define lua_isnil(L,n)		(lua_type(L, (n)) == LUA_TNIL)
26821d3294cSantirez #define lua_isboolean(L,n)	(lua_type(L, (n)) == LUA_TBOOLEAN)
26921d3294cSantirez #define lua_isthread(L,n)	(lua_type(L, (n)) == LUA_TTHREAD)
27021d3294cSantirez #define lua_isnone(L,n)		(lua_type(L, (n)) == LUA_TNONE)
27121d3294cSantirez #define lua_isnoneornil(L, n)	(lua_type(L, (n)) <= 0)
27221d3294cSantirez 
27321d3294cSantirez #define lua_pushliteral(L, s)	\
27421d3294cSantirez 	lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
27521d3294cSantirez 
27621d3294cSantirez #define lua_setglobal(L,s)	lua_setfield(L, LUA_GLOBALSINDEX, (s))
27721d3294cSantirez #define lua_getglobal(L,s)	lua_getfield(L, LUA_GLOBALSINDEX, (s))
27821d3294cSantirez 
27921d3294cSantirez #define lua_tostring(L,i)	lua_tolstring(L, (i), NULL)
28021d3294cSantirez 
28121d3294cSantirez 
28221d3294cSantirez 
28321d3294cSantirez /*
28421d3294cSantirez ** compatibility macros and functions
28521d3294cSantirez */
28621d3294cSantirez 
28721d3294cSantirez #define lua_open()	luaL_newstate()
28821d3294cSantirez 
28921d3294cSantirez #define lua_getregistry(L)	lua_pushvalue(L, LUA_REGISTRYINDEX)
29021d3294cSantirez 
29121d3294cSantirez #define lua_getgccount(L)	lua_gc(L, LUA_GCCOUNT, 0)
29221d3294cSantirez 
29321d3294cSantirez #define lua_Chunkreader		lua_Reader
29421d3294cSantirez #define lua_Chunkwriter		lua_Writer
29521d3294cSantirez 
29621d3294cSantirez 
29721d3294cSantirez /* hack */
29821d3294cSantirez LUA_API void lua_setlevel	(lua_State *from, lua_State *to);
29921d3294cSantirez 
30021d3294cSantirez 
30121d3294cSantirez /*
30221d3294cSantirez ** {======================================================================
30321d3294cSantirez ** Debug API
30421d3294cSantirez ** =======================================================================
30521d3294cSantirez */
30621d3294cSantirez 
30721d3294cSantirez 
30821d3294cSantirez /*
30921d3294cSantirez ** Event codes
31021d3294cSantirez */
31121d3294cSantirez #define LUA_HOOKCALL	0
31221d3294cSantirez #define LUA_HOOKRET	1
31321d3294cSantirez #define LUA_HOOKLINE	2
31421d3294cSantirez #define LUA_HOOKCOUNT	3
31521d3294cSantirez #define LUA_HOOKTAILRET 4
31621d3294cSantirez 
31721d3294cSantirez 
31821d3294cSantirez /*
31921d3294cSantirez ** Event masks
32021d3294cSantirez */
32121d3294cSantirez #define LUA_MASKCALL	(1 << LUA_HOOKCALL)
32221d3294cSantirez #define LUA_MASKRET	(1 << LUA_HOOKRET)
32321d3294cSantirez #define LUA_MASKLINE	(1 << LUA_HOOKLINE)
32421d3294cSantirez #define LUA_MASKCOUNT	(1 << LUA_HOOKCOUNT)
32521d3294cSantirez 
32621d3294cSantirez typedef struct lua_Debug lua_Debug;  /* activation record */
32721d3294cSantirez 
32821d3294cSantirez 
32921d3294cSantirez /* Functions to be called by the debuger in specific events */
33021d3294cSantirez typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
33121d3294cSantirez 
33221d3294cSantirez 
33321d3294cSantirez LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
33421d3294cSantirez LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
33521d3294cSantirez LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
33621d3294cSantirez LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
33721d3294cSantirez LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
33821d3294cSantirez LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
33921d3294cSantirez 
34021d3294cSantirez LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
34121d3294cSantirez LUA_API lua_Hook lua_gethook (lua_State *L);
34221d3294cSantirez LUA_API int lua_gethookmask (lua_State *L);
34321d3294cSantirez LUA_API int lua_gethookcount (lua_State *L);
34421d3294cSantirez 
34521d3294cSantirez 
34621d3294cSantirez struct lua_Debug {
34721d3294cSantirez   int event;
34821d3294cSantirez   const char *name;	/* (n) */
34921d3294cSantirez   const char *namewhat;	/* (n) `global', `local', `field', `method' */
35021d3294cSantirez   const char *what;	/* (S) `Lua', `C', `main', `tail' */
35121d3294cSantirez   const char *source;	/* (S) */
35221d3294cSantirez   int currentline;	/* (l) */
35321d3294cSantirez   int nups;		/* (u) number of upvalues */
35421d3294cSantirez   int linedefined;	/* (S) */
35521d3294cSantirez   int lastlinedefined;	/* (S) */
35621d3294cSantirez   char short_src[LUA_IDSIZE]; /* (S) */
35721d3294cSantirez   /* private part */
35821d3294cSantirez   int i_ci;  /* active function */
35921d3294cSantirez };
36021d3294cSantirez 
36121d3294cSantirez /* }====================================================================== */
36221d3294cSantirez 
36321d3294cSantirez 
36421d3294cSantirez /******************************************************************************
365*214adc50Santirez * Copyright (C) 1994-2012 Lua.org, PUC-Rio.  All rights reserved.
36621d3294cSantirez *
36721d3294cSantirez * Permission is hereby granted, free of charge, to any person obtaining
36821d3294cSantirez * a copy of this software and associated documentation files (the
36921d3294cSantirez * "Software"), to deal in the Software without restriction, including
37021d3294cSantirez * without limitation the rights to use, copy, modify, merge, publish,
37121d3294cSantirez * distribute, sublicense, and/or sell copies of the Software, and to
37221d3294cSantirez * permit persons to whom the Software is furnished to do so, subject to
37321d3294cSantirez * the following conditions:
37421d3294cSantirez *
37521d3294cSantirez * The above copyright notice and this permission notice shall be
37621d3294cSantirez * included in all copies or substantial portions of the Software.
37721d3294cSantirez *
37821d3294cSantirez * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37921d3294cSantirez * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38021d3294cSantirez * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38121d3294cSantirez * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38221d3294cSantirez * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
38321d3294cSantirez * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
38421d3294cSantirez * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38521d3294cSantirez ******************************************************************************/
38621d3294cSantirez 
38721d3294cSantirez 
38821d3294cSantirez #endif
389