lua.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. ** $Id: lua.h,v 1.19 1998/06/02 20:37:04 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. */
  8. /*********************************************************************
  9. * Copyright (c) 1994-1998 TeCGraf, PUC-Rio.
  10. * Written by Waldemar Celes Filho, Roberto Ierusalimschy and
  11. * Luiz Henrique de Figueiredo.
  12. * All rights reserved.
  13. *
  14. * Permission is hereby granted, without written agreement and with­
  15. * out license or royalty fees, to use, copy, modify, and distribute
  16. * this software and its documentation for any purpose, subject to
  17. * the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall ap­
  20. * pear in all copies or substantial portions of this software.
  21. *
  22. * The name "Lua" cannot be used for any modified form of this soft­
  23. * ware that does not originate from the authors. Nevertheless, the
  24. * name "Lua" may and should be used to designate the language im­
  25. * plemented and described in this package, even if embedded in any
  26. * other system, as long as its syntax and semantics remain un­
  27. * changed.
  28. *
  29. * The authors specifically disclaim any warranties, including, but
  30. * not limited to, the implied warranties of merchantability and
  31. * fitness for a particular purpose. The software provided hereunder
  32. * is on an "as is" basis, and the authors have no obligation to
  33. * provide maintenance, support, updates, enhancements, or modifica­
  34. * tions. In no event shall TeCGraf, PUC-Rio, or the authors be li­
  35. * able to any party for direct, indirect, special, incidental, or
  36. * consequential damages arising out of the use of this software and
  37. * its documentation.
  38. *********************************************************************/
  39. #ifndef lua_h
  40. #define lua_h
  41. #define LUA_VERSION "Lua 3.1"
  42. #define LUA_COPYRIGHT "Copyright (C) 1994-1998 TeCGraf"
  43. #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
  44. #define LUA_NOOBJECT 0
  45. #define LUA_ANYTAG (-1)
  46. typedef void (*lua_CFunction) (void);
  47. typedef unsigned int lua_Object;
  48. typedef struct lua_State lua_State;
  49. extern lua_State *lua_state;
  50. void lua_open (void);
  51. void lua_close (void);
  52. lua_State *lua_setstate (lua_State *st);
  53. lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
  54. lua_Object lua_gettagmethod (int tag, char *event);
  55. lua_Object lua_seterrormethod (void); /* In: new method */
  56. int lua_newtag (void);
  57. int lua_copytagmethods (int tagto, int tagfrom);
  58. void lua_settag (int tag); /* In: object */
  59. void lua_error (char *s);
  60. int lua_dofile (char *filename); /* Out: returns */
  61. int lua_dostring (char *string); /* Out: returns */
  62. int lua_dobuffer (char *buff, int size);
  63. /* Out: returns */
  64. int lua_callfunction (lua_Object f);
  65. /* In: parameters; Out: returns */
  66. void lua_beginblock (void);
  67. void lua_endblock (void);
  68. lua_Object lua_lua2C (int number);
  69. #define lua_getparam(_) lua_lua2C(_)
  70. #define lua_getresult(_) lua_lua2C(_)
  71. int lua_isnil (lua_Object object);
  72. int lua_istable (lua_Object object);
  73. int lua_isuserdata (lua_Object object);
  74. int lua_iscfunction (lua_Object object);
  75. int lua_isnumber (lua_Object object);
  76. int lua_isstring (lua_Object object);
  77. int lua_isfunction (lua_Object object);
  78. double lua_getnumber (lua_Object object);
  79. char *lua_getstring (lua_Object object);
  80. long lua_strlen (lua_Object object);
  81. lua_CFunction lua_getcfunction (lua_Object object);
  82. void *lua_getuserdata (lua_Object object);
  83. void lua_pushnil (void);
  84. void lua_pushnumber (double n);
  85. void lua_pushlstring (char *s, long len);
  86. void lua_pushstring (char *s);
  87. void lua_pushcclosure (lua_CFunction fn, int n);
  88. void lua_pushusertag (void *u, int tag);
  89. void lua_pushobject (lua_Object object);
  90. lua_Object lua_pop (void);
  91. lua_Object lua_getglobal (char *name);
  92. lua_Object lua_rawgetglobal (char *name);
  93. void lua_setglobal (char *name); /* In: value */
  94. void lua_rawsetglobal (char *name); /* In: value */
  95. void lua_settable (void); /* In: table, index, value */
  96. void lua_rawsettable (void); /* In: table, index, value */
  97. lua_Object lua_gettable (void); /* In: table, index */
  98. lua_Object lua_rawgettable (void); /* In: table, index */
  99. int lua_tag (lua_Object object);
  100. int lua_ref (int lock); /* In: value */
  101. lua_Object lua_getref (int ref);
  102. void lua_unref (int ref);
  103. lua_Object lua_createtable (void);
  104. long lua_collectgarbage (long limit);
  105. /* =============================================================== */
  106. /* some useful macros/derived functions */
  107. int (lua_call) (char *name);
  108. #define lua_call(name) lua_callfunction(lua_getglobal(name))
  109. void (lua_pushref) (int ref);
  110. #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
  111. int (lua_refobject) (lua_Object o, int l);
  112. #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
  113. void (lua_register) (char *n, lua_CFunction f);
  114. #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
  115. void (lua_pushuserdata) (void *u);
  116. #define lua_pushuserdata(u) lua_pushusertag(u, 0)
  117. void (lua_pushcfunction) (lua_CFunction f);
  118. #define lua_pushcfunction(f) lua_pushcclosure(f, 0)
  119. int (lua_clonetag) (int t);
  120. #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
  121. /* ==========================================================================
  122. ** for compatibility with old versions. Avoid using these macros/functions
  123. ** If your program does need any of these, define LUA_COMPAT2_5
  124. */
  125. #ifdef LUA_COMPAT2_5
  126. lua_Object lua_setfallback (char *event, lua_CFunction fallback);
  127. #define lua_storeglobal lua_setglobal
  128. #define lua_type lua_tag
  129. #define lua_lockobject(o) lua_refobject(o,1)
  130. #define lua_lock() lua_ref(1)
  131. #define lua_getlocked lua_getref
  132. #define lua_pushlocked lua_pushref
  133. #define lua_unlock lua_unref
  134. #define lua_pushliteral(o) lua_pushstring(o)
  135. #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
  136. #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
  137. #define lua_copystring(o) (strdup(lua_getstring(o)))
  138. #define lua_getsubscript lua_gettable
  139. #define lua_storesubscript lua_settable
  140. #endif
  141. #endif