lua.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. ** LUA - Linguagem para Usuarios de Aplicacao
  3. ** Grupo de Tecnologia em Computacao Grafica
  4. ** TeCGraf - PUC-Rio
  5. ** $Id: lua.h,v 3.15 1995/01/18 20:15:05 celes Exp celes $
  6. */
  7. #ifndef lua_h
  8. #define lua_h
  9. /* Private Part */
  10. typedef enum
  11. {
  12. LUA_T_NIL = -1,
  13. LUA_T_NUMBER = -2,
  14. LUA_T_STRING = -3,
  15. LUA_T_ARRAY = -4,
  16. LUA_T_FUNCTION = -5,
  17. LUA_T_CFUNCTION= -6,
  18. LUA_T_USERDATA = 0
  19. } lua_Type;
  20. /* Public Part */
  21. #define LUA_NOOBJECT 0
  22. typedef void (*lua_CFunction) (void);
  23. typedef unsigned int lua_Object;
  24. lua_Object lua_setfallback (char *name, lua_CFunction fallback);
  25. void lua_error (char *s);
  26. int lua_dofile (char *filename);
  27. int lua_dostring (char *string);
  28. int lua_callfunction (lua_Object function);
  29. int lua_call (char *funcname);
  30. void lua_beginblock (void);
  31. void lua_endblock (void);
  32. lua_Object lua_getparam (int number);
  33. #define lua_getresult(_) lua_getparam(_)
  34. float lua_getnumber (lua_Object object);
  35. char *lua_getstring (lua_Object object);
  36. lua_CFunction lua_getcfunction (lua_Object object);
  37. void *lua_getuserdata (lua_Object object);
  38. void lua_pushnil (void);
  39. void lua_pushnumber (float n);
  40. void lua_pushstring (char *s);
  41. void lua_pushliteral (char *s);
  42. void lua_pushcfunction (lua_CFunction fn);
  43. void lua_pushusertag (void *u, int tag);
  44. void lua_pushobject (lua_Object object);
  45. lua_Object lua_getglobal (char *name);
  46. void lua_storeglobal (char *name);
  47. void lua_storesubscript (void);
  48. lua_Object lua_getsubscript (void);
  49. int lua_type (lua_Object object);
  50. int lua_lock (void);
  51. lua_Object lua_getlocked (int ref);
  52. void lua_pushlocked (int ref);
  53. void lua_unlock (int ref);
  54. lua_Object lua_createtable (void);
  55. /* some useful macros */
  56. #define lua_lockobject(o) (lua_pushobject(o), lua_lock())
  57. #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n))
  58. #define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA)
  59. #define lua_isnil(_) (lua_type(_)==LUA_T_NIL)
  60. #define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER)
  61. #define lua_isstring(_) (lua_type(_)==LUA_T_STRING)
  62. #define lua_istable(_) (lua_type(_)==LUA_T_ARRAY)
  63. #define lua_isfunction(_) (lua_type(_)==LUA_T_FUNCTION)
  64. #define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION)
  65. #define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA)
  66. /* for lua 1.1 compatibility. Avoid using these macros */
  67. #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
  68. #define lua_getfield(o,f) (lua_pushobject(o), lua_pushliteral(f), lua_getsubscript())
  69. #define lua_copystring(o) (strdup(lua_getstring(o)))
  70. #endif