lua.h 5.9 KB

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