lua.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. ** $Id: lua.h,v 1.13 1998/01/02 17:46:32 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 (alpha)"
  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. void lua_open (void);
  49. void lua_close (void);
  50. lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
  51. lua_Object lua_gettagmethod (int tag, char *event);
  52. lua_Object lua_seterrormethod (void); /* In: new method */
  53. int lua_newtag (void);
  54. int lua_copytagmethods (int tagto, int tagfrom);
  55. void lua_settag (int tag); /* In: object */
  56. void lua_error (char *s);
  57. int lua_dofile (char *filename); /* Out: returns */
  58. int lua_dostring (char *string); /* Out: returns */
  59. int lua_callfunction (lua_Object f);
  60. /* In: parameters; Out: returns */
  61. void lua_beginblock (void);
  62. void lua_endblock (void);
  63. lua_Object lua_lua2C (int number);
  64. #define lua_getparam(_) lua_lua2C(_)
  65. #define lua_getresult(_) lua_lua2C(_)
  66. int lua_isnil (lua_Object object);
  67. int lua_istable (lua_Object object);
  68. int lua_isuserdata (lua_Object object);
  69. int lua_iscfunction (lua_Object object);
  70. int lua_isnumber (lua_Object object);
  71. int lua_isstring (lua_Object object);
  72. int lua_isfunction (lua_Object object);
  73. double lua_getnumber (lua_Object object);
  74. char *lua_getstring (lua_Object object);
  75. lua_CFunction lua_getcfunction (lua_Object object);
  76. void *lua_getuserdata (lua_Object object);
  77. void lua_pushnil (void);
  78. void lua_pushnumber (double n);
  79. void lua_pushstring (char *s);
  80. void lua_pushCclosure (lua_CFunction fn, int n);
  81. void lua_pushusertag (void *u, int tag);
  82. void lua_pushobject (lua_Object object);
  83. lua_Object lua_pop (void);
  84. lua_Object lua_getglobal (char *name);
  85. lua_Object lua_rawgetglobal (char *name);
  86. void lua_setglobal (char *name); /* In: value */
  87. void lua_rawsetglobal (char *name); /* In: value */
  88. void lua_settable (void); /* In: table, index, value */
  89. void lua_rawsettable (void); /* In: table, index, value */
  90. lua_Object lua_gettable (void); /* In: table, index */
  91. lua_Object lua_rawgettable (void); /* In: table, index */
  92. int lua_tag (lua_Object object);
  93. int lua_ref (int lock); /* In: value */
  94. lua_Object lua_getref (int ref);
  95. void lua_unref (int ref);
  96. lua_Object lua_createtable (void);
  97. long lua_collectgarbage (long limit);
  98. /* =============================================================== */
  99. /* some useful macros */
  100. #define lua_call(name) lua_callfunction(lua_getglobal(name))
  101. #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
  102. #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
  103. #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
  104. #define lua_pushuserdata(u) lua_pushusertag(u, 0)
  105. #define lua_pushcfunction(f) lua_pushCclosure(f, 0)
  106. #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
  107. /* ==========================================================================
  108. ** for compatibility with old versions. Avoid using these macros/functions
  109. ** If your program does need any of these, define LUA_COMPAT2_5
  110. */
  111. #ifdef LUA_COMPAT2_5
  112. lua_Object lua_setfallback (char *event, lua_CFunction fallback);
  113. #define lua_storeglobal lua_setglobal
  114. #define lua_type lua_tag
  115. #define lua_lockobject(o) lua_refobject(o,1)
  116. #define lua_lock() lua_ref(1)
  117. #define lua_getlocked lua_getref
  118. #define lua_pushlocked lua_pushref
  119. #define lua_unlock lua_unref
  120. #define lua_pushliteral(o) lua_pushstring(o)
  121. #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
  122. #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
  123. #define lua_copystring(o) (strdup(lua_getstring(o)))
  124. #define lua_getsubscript lua_gettable
  125. #define lua_storesubscript lua_settable
  126. #endif
  127. #endif