lua.h 11 KB

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