tolua++.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* tolua
  2. ** Support code for Lua bindings.
  3. ** Written by Waldemar Celes
  4. ** TeCGraf/PUC-Rio
  5. ** Apr 2003
  6. ** $Id: $
  7. */
  8. /* This code is free software; you can redistribute it and/or modify it.
  9. ** The software provided hereunder is on an "as is" basis, and
  10. ** the author has no obligation to provide maintenance, support, updates,
  11. ** enhancements, or modifications.
  12. */
  13. #ifndef TOLUA_H
  14. #define TOLUA_H
  15. #ifndef TOLUA_API
  16. #define TOLUA_API extern
  17. #endif
  18. #define TOLUA_VERSION "tolua++-1.0.93"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define tolua_pushcppstring(x,y) tolua_pushstring(x,y.c_str())
  23. #define tolua_iscppstring tolua_isstring
  24. #define tolua_iscppstringarray tolua_isstringarray
  25. #define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str())
  26. #ifndef TEMPLATE_BIND
  27. #define TEMPLATE_BIND(p)
  28. #endif
  29. #define TOLUA_TEMPLATE_BIND(p)
  30. #define TOLUA_PROTECTED_DESTRUCTOR
  31. #define TOLUA_PROPERTY_TYPE(p)
  32. typedef int lua_Object;
  33. #include "lua.h"
  34. #include "lauxlib.h"
  35. struct tolua_Error
  36. {
  37. int index;
  38. int array;
  39. const char* type;
  40. };
  41. typedef struct tolua_Error tolua_Error;
  42. #define TOLUA_NOPEER LUA_REGISTRYINDEX /* for lua 5.1 */
  43. TOLUA_API const char* tolua_typename (lua_State* L, int lo);
  44. TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err);
  45. TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err);
  46. TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err);
  47. TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err);
  48. TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err);
  49. TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err);
  50. TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err);
  51. TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err);
  52. TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  53. TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err);
  54. TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  55. TOLUA_API int tolua_isvaluearray
  56. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  57. TOLUA_API int tolua_isbooleanarray
  58. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  59. TOLUA_API int tolua_isnumberarray
  60. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  61. TOLUA_API int tolua_isstringarray
  62. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  63. TOLUA_API int tolua_istablearray
  64. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  65. TOLUA_API int tolua_isuserdataarray
  66. (lua_State* L, int lo, int dim, int def, tolua_Error* err);
  67. TOLUA_API int tolua_isusertypearray
  68. (lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err);
  69. TOLUA_API void tolua_open (lua_State* L);
  70. TOLUA_API void* tolua_copy (lua_State* L, void* value, unsigned int size);
  71. TOLUA_API int tolua_register_gc (lua_State* L, int lo);
  72. TOLUA_API int tolua_default_collect (lua_State* tolua_S);
  73. TOLUA_API void tolua_usertype (lua_State* L, const char* type);
  74. TOLUA_API void tolua_beginmodule (lua_State* L, const char* name);
  75. TOLUA_API void tolua_endmodule (lua_State* L);
  76. TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar);
  77. TOLUA_API void tolua_class (lua_State* L, const char* name, const char* base);
  78. TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col);
  79. TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func);
  80. TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value);
  81. TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set);
  82. TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set);
  83. /* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */
  84. /* TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base); */
  85. TOLUA_API void tolua_pushvalue (lua_State* L, int lo);
  86. TOLUA_API void tolua_pushboolean (lua_State* L, int value);
  87. TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value);
  88. TOLUA_API void tolua_pushstring (lua_State* L, const char* value);
  89. TOLUA_API void tolua_pushuserdata (lua_State* L, void* value);
  90. TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type);
  91. TOLUA_API void tolua_pushusertype_and_takeownership(lua_State* L, void* value, const char* type);
  92. TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v);
  93. TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v);
  94. TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v);
  95. TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v);
  96. TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v);
  97. TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type);
  98. TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type);
  99. TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def);
  100. TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def);
  101. TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def);
  102. TOLUA_API void* tolua_tousertype (lua_State* L, int narg, void* def);
  103. TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def);
  104. TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def);
  105. TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def);
  106. TOLUA_API const char* tolua_tofieldstring (lua_State* L, int lo, int index, const char* def);
  107. TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def);
  108. TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def);
  109. TOLUA_API int tolua_tofieldvalue (lua_State* L, int lo, int index, int def);
  110. TOLUA_API int tolua_getfieldboolean (lua_State* L, int lo, int index, int def);
  111. TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name);
  112. TOLUA_API int class_gc_event (lua_State* L);
  113. #ifdef __cplusplus
  114. static inline const char* tolua_tocppstring (lua_State* L, int narg, const char* def) {
  115. const char* s = tolua_tostring(L, narg, def);
  116. return s?s:"";
  117. }
  118. static inline const char* tolua_tofieldcppstring (lua_State* L, int lo, int index, const char* def) {
  119. const char* s = tolua_tofieldstring(L, lo, index, def);
  120. return s?s:"";
  121. }
  122. #else
  123. #define tolua_tocppstring tolua_tostring
  124. #define tolua_tofieldcppstring tolua_tofieldstring
  125. #endif
  126. TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index);
  127. #ifndef Mtolua_new
  128. #define Mtolua_new(EXP) new EXP
  129. #endif
  130. #ifndef Mtolua_delete
  131. #define Mtolua_delete(EXP) delete EXP
  132. #endif
  133. #ifndef Mtolua_new_dim
  134. #define Mtolua_new_dim(EXP, len) new EXP[len]
  135. #endif
  136. #ifndef Mtolua_delete_dim
  137. #define Mtolua_delete_dim(EXP) delete [] EXP
  138. #endif
  139. #ifndef tolua_outside
  140. #define tolua_outside
  141. #endif
  142. #ifndef tolua_owned
  143. #define tolua_owned
  144. #endif
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif