lua.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. ** $Id: lua.h,v 1.57 2000/08/09 19:16:57 roberto Exp roberto $
  3. ** Lua - An Extensible Extension Language
  4. ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
  5. ** e-mail: [email protected]
  6. ** www: http://www.tecgraf.puc-rio.br/lua/
  7. ** See Copyright Notice at the end of this file
  8. */
  9. #ifndef lua_h
  10. #define lua_h
  11. /* definition of `size_t' */
  12. #include <stddef.h>
  13. #define LUA_VERSION "Lua 4.0 (beta)"
  14. #define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
  15. #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
  16. #define LUA_ALERT "_ALERT"
  17. #define LUA_ERRORMESSAGE "_ERRORMESSAGE"
  18. #define LUA_NOREF (-2)
  19. #define LUA_REFNIL (-1)
  20. #define LUA_ANYTAG (-1)
  21. /* error code for lua_do* */
  22. #define LUA_ERRFILE 2
  23. #define LUA_ERRSYNTAX 3
  24. #define LUA_ERRRUN 1
  25. #define LUA_ERRMEM 4
  26. typedef struct lua_State lua_State;
  27. typedef void (*lua_CFunction) (lua_State *L);
  28. typedef struct lua_TObject *lua_Object;
  29. #define LUA_NOOBJECT ((lua_Object)0)
  30. lua_State *lua_newstate (int stacksize, int builtin);
  31. void lua_close (lua_State *L);
  32. lua_Object lua_settagmethod (lua_State *L, int tag, const char *event);
  33. /* In: new method */
  34. lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event);
  35. int lua_newtag (lua_State *L);
  36. int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
  37. void lua_settag (lua_State *L, int tag); /* In: object */
  38. void lua_error (lua_State *L, const char *s);
  39. int lua_dofile (lua_State *L, const char *filename);
  40. /* Out: returns */
  41. int lua_dostring (lua_State *L, const char *str);
  42. /* Out: returns */
  43. int lua_dobuffer (lua_State *L, const char *buff, size_t size,
  44. const char *name); /* Out: returns */
  45. int lua_callfunction (lua_State *L, lua_Object f);
  46. /* In: arguments; Out: returns */
  47. void lua_beginblock (lua_State *L);
  48. void lua_endblock (lua_State *L);
  49. void lua_pushglobals (lua_State *L);
  50. void lua_setglobals (lua_State *L, lua_Object newtable);
  51. lua_Object lua_lua2C (lua_State *L, int number);
  52. #define lua_getparam lua_lua2C
  53. #define lua_getresult lua_lua2C
  54. const char *lua_type (lua_State *L, lua_Object obj);
  55. int lua_isnil (lua_State *L, lua_Object obj);
  56. int lua_istable (lua_State *L, lua_Object obj);
  57. int lua_isuserdata (lua_State *L, lua_Object obj);
  58. int lua_iscfunction (lua_State *L, lua_Object obj);
  59. int lua_isnumber (lua_State *L, lua_Object obj);
  60. int lua_isstring (lua_State *L, lua_Object obj);
  61. int lua_isfunction (lua_State *L, lua_Object obj);
  62. int lua_equal (lua_State *L, lua_Object o1, lua_Object o2);
  63. double lua_getnumber (lua_State *L, lua_Object obj);
  64. const char *lua_getstring (lua_State *L, lua_Object obj);
  65. size_t lua_strlen (lua_State *L, lua_Object obj);
  66. lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj);
  67. void *lua_getuserdata (lua_State *L, lua_Object obj);
  68. void lua_pushnil (lua_State *L);
  69. void lua_pushnumber (lua_State *L, double n);
  70. void lua_pushlstring (lua_State *L, const char *s, size_t len);
  71. void lua_pushstring (lua_State *L, const char *s);
  72. void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
  73. void lua_pushusertag (lua_State *L, void *u, int tag);
  74. void lua_pushobject (lua_State *L, lua_Object obj);
  75. lua_Object lua_pop (lua_State *L);
  76. lua_Object lua_getglobal (lua_State *L, const char *name);
  77. void lua_setglobal (lua_State *L, const char *name); /* In: value */
  78. void lua_settable (lua_State *L); /* In: table, index, value */
  79. lua_Object lua_gettable (lua_State *L); /* In: table, index */
  80. void lua_rawset (lua_State *L); /* In: table, index, value */
  81. lua_Object lua_rawget (lua_State *L); /* In: table, index */
  82. int lua_tag (lua_State *L, lua_Object obj);
  83. int lua_next (lua_State *L, lua_Object o, int i);
  84. /* Out: index, value */
  85. int lua_ref (lua_State *L, int lock); /* In: value */
  86. lua_Object lua_getref (lua_State *L, int ref);
  87. void lua_unref (lua_State *L, int ref);
  88. lua_Object lua_createtable (lua_State *L);
  89. long lua_collectgarbage (lua_State *L, long limit);
  90. /*
  91. ** ===============================================================
  92. ** some useful macros
  93. ** ===============================================================
  94. */
  95. #ifndef LUA_SINGLESTATE
  96. #define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name))
  97. #define lua_pushref(L,ref) lua_pushobject(L, lua_getref(L, ref))
  98. #define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l))
  99. #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
  100. #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0)
  101. #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
  102. #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t))
  103. #else
  104. #define lua_call(name) lua_callfunction(lua_getglobal(name))
  105. #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
  106. #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
  107. #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
  108. #define lua_pushuserdata(u) lua_pushusertag(u, 0)
  109. #define lua_pushcfunction(f) lua_pushcclosure(f, 0)
  110. #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
  111. #endif
  112. #ifdef LUA_SINGLESTATE
  113. /*
  114. ** {==============================================================
  115. ** Macros for single-state use
  116. ** ===============================================================
  117. */
  118. extern lua_State *lua_state;
  119. #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0, 1))))
  120. #define lua_close() (lua_close)(lua_state)
  121. #define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event)
  122. #define lua_gettagmethod(tag,event) (lua_gettagmethod)(lua_state, tag,event)
  123. #define lua_newtag() (lua_newtag)(lua_state)
  124. #define lua_copytagmethods(tagto,tagfrom) \
  125. (lua_copytagmethods)(lua_state, tagto,tagfrom)
  126. #define lua_settag(tag) (lua_settag)(lua_state, tag)
  127. #define lua_error(s) (lua_error)(lua_state, s)
  128. #define lua_dofile(filename) (lua_dofile)(lua_state, filename)
  129. #define lua_dostring(str) (lua_dostring)(lua_state, str)
  130. #define lua_dobuffer(b,s,n) (lua_dobuffer)(lua_state, b,s,n)
  131. #define lua_callfunction(f) (lua_callfunction)(lua_state, f)
  132. #define lua_beginblock() (lua_beginblock)(lua_state)
  133. #define lua_endblock() (lua_endblock)(lua_state)
  134. #define lua_pushglobals() (lua_pushglobals)(lua_state)
  135. #define lua_setglobals(t) (lua_setglobals)(lua_state, t)
  136. #define lua_lua2C(number) (lua_lua2C)(lua_state, number)
  137. #define lua_type(obj) (lua_type)(lua_state, obj)
  138. #define lua_isnil(obj) (lua_isnil)(lua_state, obj)
  139. #define lua_istable(obj) (lua_istable)(lua_state, obj)
  140. #define lua_isuserdata(obj) (lua_isuserdata)(lua_state, obj)
  141. #define lua_iscfunction(obj) (lua_iscfunction)(lua_state, obj)
  142. #define lua_isnumber(obj) (lua_isnumber)(lua_state, obj)
  143. #define lua_isstring(obj) (lua_isstring)(lua_state, obj)
  144. #define lua_isfunction(obj) (lua_isfunction)(lua_state, obj)
  145. #define lua_equal(o1,o2) (lua_equal)(lua_state, o1,o2)
  146. #define lua_getnumber(obj) (lua_getnumber)(lua_state, obj)
  147. #define lua_getstring(obj) (lua_getstring)(lua_state, obj)
  148. #define lua_strlen(obj) (lua_strlen)(lua_state, obj)
  149. #define lua_getcfunction(obj) (lua_getcfunction)(lua_state, obj)
  150. #define lua_getuserdata(obj) (lua_getuserdata)(lua_state, obj)
  151. #define lua_pushnil() (lua_pushnil)(lua_state)
  152. #define lua_pushnumber(n) (lua_pushnumber)(lua_state, n)
  153. #define lua_pushlstring(s,len) (lua_pushlstring)(lua_state, s,len)
  154. #define lua_pushstring(s) (lua_pushstring)(lua_state, s)
  155. #define lua_pushusertag(u,tag) (lua_pushusertag)(lua_state, u,tag)
  156. #define lua_pushobject(obj) (lua_pushobject)(lua_state, obj)
  157. #define lua_pop() (lua_pop)(lua_state)
  158. #define lua_getglobal(name) (lua_getglobal)(lua_state, name)
  159. #define lua_setglobal(name) (lua_setglobal)(lua_state, name)
  160. #define lua_settable() (lua_settable)(lua_state)
  161. #define lua_gettable() (lua_gettable)(lua_state)
  162. #define lua_rawset() (lua_rawset)(lua_state)
  163. #define lua_rawget() (lua_rawget)(lua_state)
  164. #define lua_tag(obj) (lua_tag)(lua_state, obj)
  165. #define lua_next(o,i) (lua_next)(lua_state, o,i)
  166. #define lua_ref(lock) (lua_ref)(lua_state, lock)
  167. #define lua_getref(ref) (lua_getref)(lua_state, ref)
  168. #define lua_unref(ref) (lua_unref)(lua_state, ref)
  169. #define lua_createtable() (lua_createtable)(lua_state)
  170. #define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit)
  171. /*
  172. ** the following typecast is a little dirty, but we know of no other
  173. ** way to keep compatibility with old definition of `lua_CFunction'
  174. */
  175. #define lua_pushcclosure(fn,n) \
  176. (lua_pushcclosure)(lua_state, (lua_CFunction)(fn), n)
  177. /*
  178. ** }==============================================================
  179. */
  180. #endif
  181. /*
  182. ** compatibility with 3.2
  183. ** these functions are only available when Lua is compiled with
  184. ** the option LUA_DEPRECATETFUNCS
  185. */
  186. #define lua_rawsettable lua_rawset
  187. #define lua_rawgettable lua_rawget
  188. lua_Object lua_rawgetglobal (lua_State *L, const char *name);
  189. void lua_rawsetglobal (lua_State *L, const char *name);/* In: value */
  190. #ifdef LUA_SINGLESTATE
  191. #define lua_rawgetglobal(name) (lua_rawgetglobal(lua_state, name))
  192. #define lua_rawsetglobal(name) (lua_rawsetglobal(lua_state, name))
  193. #endif
  194. #endif
  195. /******************************************************************************
  196. * Copyright (C) 1994-2000 TeCGraf, PUC-Rio. All rights reserved.
  197. *
  198. * Permission is hereby granted, without written agreement and without license
  199. * or royalty fees, to use, copy, modify, and distribute this software and its
  200. * documentation for any purpose, including commercial applications, subject to
  201. * the following conditions:
  202. *
  203. * - The above copyright notice and this permission notice shall appear in all
  204. * copies or substantial portions of this software.
  205. *
  206. * - The origin of this software must not be misrepresented; you must not
  207. * claim that you wrote the original software. If you use this software in a
  208. * product, an acknowledgment in the product documentation would be greatly
  209. * appreciated (but it is not required).
  210. *
  211. * - Altered source versions must be plainly marked as such, and must not be
  212. * misrepresented as being the original software.
  213. *
  214. * The authors specifically disclaim any warranties, including, but not limited
  215. * to, the implied warranties of merchantability and fitness for a particular
  216. * purpose. The software provided hereunder is on an "as is" basis, and the
  217. * authors have no obligation to provide maintenance, support, updates,
  218. * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
  219. * authors be held liable to any party for direct, indirect, special,
  220. * incidental, or consequential damages arising out of the use of this software
  221. * and its documentation.
  222. *
  223. * The Lua language and this implementation have been entirely designed and
  224. * written by Waldemar Celes Filho, Roberto Ierusalimschy and
  225. * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
  226. *
  227. * This implementation contains no third-party code.
  228. ******************************************************************************/