lauxlib.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** $Id: lauxlib.h,v 1.24 2000/09/11 20:29:27 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. struct luaL_reg {
  12. const char *name;
  13. lua_CFunction func;
  14. };
  15. void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
  16. void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
  17. const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
  18. const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def,
  19. size_t *len);
  20. double luaL_check_number (lua_State *L, int numArg);
  21. double luaL_opt_number (lua_State *L, int numArg, double def);
  22. void luaL_checkstack (lua_State *L, int space, const char *msg);
  23. void luaL_checktype (lua_State *L, int narg, const char *tname);
  24. void luaL_verror (lua_State *L, const char *fmt, ...);
  25. int luaL_findstring (const char *name, const char *const list[]);
  26. /*
  27. ** ===============================================================
  28. ** some useful macros
  29. ** ===============================================================
  30. */
  31. #define luaL_arg_check(L, cond,numarg,extramsg) if (!(cond)) \
  32. luaL_argerror(L, numarg,extramsg)
  33. #define luaL_check_string(L,n) (luaL_check_lstr(L, (n), NULL))
  34. #define luaL_opt_string(L,n,d) (luaL_opt_lstr(L, (n), (d), NULL))
  35. #define luaL_check_int(L,n) ((int)luaL_check_number(L, n))
  36. #define luaL_check_long(L,n) ((long)luaL_check_number(L, n))
  37. #define luaL_opt_int(L,n,d) ((int)luaL_opt_number(L, n,d))
  38. #define luaL_opt_long(L,n,d) ((long)luaL_opt_number(L, n,d))
  39. #define luaL_openl(L,a) luaL_openlib(L, a, (sizeof(a)/sizeof(a[0])))
  40. /*
  41. ** {======================================================
  42. ** Generic Buffer manipulation
  43. ** =======================================================
  44. */
  45. #define LUAL_BUFFERSIZE BUFSIZ
  46. typedef struct luaL_Buffer {
  47. char *p; /* current position in buffer */
  48. int level;
  49. lua_State *L;
  50. char buffer[LUAL_BUFFERSIZE];
  51. } luaL_Buffer;
  52. #define luaL_putchar(B,c) \
  53. ((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer(B)), \
  54. (*(B)->p++ = (char)(c)))
  55. #define luaL_addsize(B,n) ((B)->p += (n))
  56. void luaL_buffinit (lua_State *L, luaL_Buffer *B);
  57. char *luaL_prepbuffer (luaL_Buffer *B);
  58. void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
  59. void luaL_addstring (luaL_Buffer *B, const char *s);
  60. void luaL_addvalue (luaL_Buffer *B);
  61. void luaL_pushresult (luaL_Buffer *B);
  62. /* }====================================================== */
  63. #endif