lua.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** LUA - An Extensible Extension Language
  3. ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
  4. ** e-mail: [email protected]
  5. ** $Id: lua.h,v 4.10 1997/06/19 18:03:04 roberto Exp roberto $
  6. */
  7. #ifndef lua_h
  8. #define lua_h
  9. #define LUA_VERSION "Lua 3.0"
  10. #define LUA_COPYRIGHT "Copyright (C) 1994-1997 TeCGraf"
  11. #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
  12. #define LUA_NOOBJECT 0
  13. #define LUA_ANYTAG (-1)
  14. typedef void (*lua_CFunction) (void);
  15. typedef unsigned int lua_Object;
  16. lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
  17. lua_Object lua_gettagmethod (int tag, char *event);
  18. lua_Object lua_seterrormethod (void); /* In: new method */
  19. int lua_newtag (void);
  20. void lua_settag (int tag); /* In: object */
  21. void lua_error (char *s);
  22. int lua_dofile (char *filename); /* Out: returns */
  23. int lua_dostring (char *string); /* Out: returns */
  24. int lua_callfunction (lua_Object f);
  25. /* In: parameters; Out: returns */
  26. void lua_beginblock (void);
  27. void lua_endblock (void);
  28. lua_Object lua_lua2C (int number);
  29. #define lua_getparam(_) lua_lua2C(_)
  30. #define lua_getresult(_) lua_lua2C(_)
  31. int lua_isnil (lua_Object object);
  32. int lua_istable (lua_Object object);
  33. int lua_isuserdata (lua_Object object);
  34. int lua_iscfunction (lua_Object object);
  35. int lua_isnumber (lua_Object object);
  36. int lua_isstring (lua_Object object);
  37. int lua_isfunction (lua_Object object);
  38. float lua_getnumber (lua_Object object);
  39. char *lua_getstring (lua_Object object);
  40. lua_CFunction lua_getcfunction (lua_Object object);
  41. void *lua_getuserdata (lua_Object object);
  42. void lua_pushnil (void);
  43. void lua_pushnumber (float n);
  44. void lua_pushstring (char *s);
  45. void lua_pushcfunction (lua_CFunction fn);
  46. void lua_pushusertag (void *u, int tag);
  47. void lua_pushobject (lua_Object object);
  48. lua_Object lua_pop (void);
  49. lua_Object lua_getglobal (char *name);
  50. lua_Object lua_rawgetglobal (char *name);
  51. void lua_setglobal (char *name); /* In: value */
  52. void lua_rawsetglobal (char *name); /* In: value */
  53. void lua_settable (void); /* In: table, index, value */
  54. void lua_rawsettable (void); /* In: table, index, value */
  55. lua_Object lua_gettable (void); /* In: table, index */
  56. lua_Object lua_rawgettable (void); /* In: table, index */
  57. int lua_tag (lua_Object object);
  58. int lua_ref (int lock); /* In: value */
  59. lua_Object lua_getref (int ref);
  60. void lua_unref (int ref);
  61. lua_Object lua_createtable (void);
  62. long lua_collectgarbage (long limit);
  63. /* =============================================================== */
  64. /* some useful macros */
  65. #define lua_call(name) lua_callfunction(lua_getglobal(name))
  66. #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
  67. #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
  68. #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
  69. #define lua_pushuserdata(u) lua_pushusertag(u, 0)
  70. /* ==========================================================================
  71. ** for compatibility with old versions. Avoid using these macros/functions
  72. ** If your program does not use any of these, define LUA_COMPAT2_5 to 0
  73. */
  74. #ifndef LUA_COMPAT2_5
  75. #define LUA_COMPAT2_5 1
  76. #endif
  77. #if LUA_COMPAT2_5
  78. lua_Object lua_setfallback (char *event, lua_CFunction fallback);
  79. #define lua_storeglobal lua_setglobal
  80. #define lua_type lua_tag
  81. #define lua_lockobject(o) lua_refobject(o,1)
  82. #define lua_lock() lua_ref(1)
  83. #define lua_getlocked lua_getref
  84. #define lua_pushlocked lua_pushref
  85. #define lua_unlock lua_unref
  86. #define lua_pushliteral(o) lua_pushstring(o)
  87. #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
  88. #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
  89. #define lua_copystring(o) (strdup(lua_getstring(o)))
  90. #define lua_getsubscript lua_gettable
  91. #define lua_storesubscript lua_settable
  92. #endif
  93. #endif