2
0

lauxlib.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. ** $Id: lauxlib.h,v 1.35 2001/04/06 21:17:37 roberto Exp roberto $
  3. ** Auxiliary functions for building Lua libraries
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lauxlib_h
  7. #define lauxlib_h
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include "lua.h"
  11. #ifndef LUALIB_API
  12. #define LUALIB_API extern
  13. #endif
  14. typedef struct luaL_reg {
  15. const lua_char *name;
  16. lua_CFunction func;
  17. } luaL_reg;
  18. LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n);
  19. LUALIB_API void luaL_argerror (lua_State *L, int numarg,
  20. const lua_char *extramsg);
  21. LUALIB_API const lua_char *luaL_check_lstr (lua_State *L, int numArg,
  22. size_t *len);
  23. LUALIB_API const lua_char *luaL_opt_lstr (lua_State *L, int numArg,
  24. const lua_char *def, size_t *len);
  25. LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg);
  26. LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def);
  27. LUALIB_API void luaL_checkstack (lua_State *L, int space, const lua_char *msg);
  28. LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
  29. LUALIB_API void luaL_checkany (lua_State *L, int narg);
  30. LUALIB_API void *luaL_check_userdata (lua_State *L, int narg,
  31. const lua_char *name);
  32. LUALIB_API void luaL_verror (lua_State *L, const lua_char *fmt, ...);
  33. LUALIB_API int luaL_findstring (const lua_char *name,
  34. const lua_char *const list[]);
  35. /*
  36. ** ===============================================================
  37. ** some useful macros
  38. ** ===============================================================
  39. */
  40. #define luaL_arg_check(L, cond,numarg,extramsg) if (!(cond)) \
  41. luaL_argerror(L, numarg,extramsg)
  42. #define luaL_check_string(L,n) (luaL_check_lstr(L, (n), NULL))
  43. #define luaL_opt_string(L,n,d) (luaL_opt_lstr(L, (n), (d), NULL))
  44. #define luaL_check_int(L,n) ((int)luaL_check_number(L, n))
  45. #define luaL_check_long(L,n) ((long)luaL_check_number(L, n))
  46. #define luaL_opt_int(L,n,d) ((int)luaL_opt_number(L, n,d))
  47. #define luaL_opt_long(L,n,d) ((long)luaL_opt_number(L, n,d))
  48. #define luaL_openl(L,a) luaL_openlib(L, a, (sizeof(a)/sizeof(a[0])))
  49. /*
  50. ** {======================================================
  51. ** Generic Buffer manipulation
  52. ** =======================================================
  53. */
  54. #ifndef LUAL_BUFFERSIZE
  55. #define LUAL_BUFFERSIZE BUFSIZ
  56. #endif
  57. typedef struct luaL_Buffer {
  58. lua_char *p; /* current position in buffer */
  59. int level;
  60. lua_State *L;
  61. lua_char buffer[LUAL_BUFFERSIZE];
  62. } luaL_Buffer;
  63. #define luaL_putchar(B,c) \
  64. ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
  65. (*(B)->p++ = (lua_char)(c)))
  66. #define luaL_addsize(B,n) ((B)->p += (n))
  67. LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
  68. LUALIB_API lua_char *luaL_prepbuffer (luaL_Buffer *B);
  69. LUALIB_API void luaL_addlstring (luaL_Buffer *B, const lua_char *s, size_t l);
  70. LUALIB_API void luaL_addstring (luaL_Buffer *B, const lua_char *s);
  71. LUALIB_API void luaL_addvalue (luaL_Buffer *B);
  72. LUALIB_API void luaL_pushresult (luaL_Buffer *B);
  73. /* }====================================================== */
  74. #endif