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