95 ** =============================================================== |
95 ** =============================================================== |
96 ** some useful macros |
96 ** some useful macros |
97 ** =============================================================== |
97 ** =============================================================== |
98 */ |
98 */ |
99 |
99 |
100 #define luaL_argcheck(L, cond,numarg,extramsg) \ |
100 #define luaL_argcheck(L, cond,numarg,extramsg) \ |
101 ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) |
101 ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) |
102 #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
102 #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
103 #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
103 #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
104 #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) |
104 #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) |
105 #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) |
105 #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) |
106 #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) |
106 #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) |
107 #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) |
107 #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) |
108 |
108 |
109 #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) |
109 #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) |
110 |
110 |
111 #define luaL_dofile(L, fn) \ |
111 #define luaL_dofile(L, fn) \ |
112 (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
112 (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
113 |
113 |
114 #define luaL_dostring(L, s) \ |
114 #define luaL_dostring(L, s) \ |
115 (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
115 (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
116 |
116 |
117 #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) |
117 #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) |
118 |
118 |
119 #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) |
119 #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) |
120 |
120 |
121 /* |
121 /* |
122 ** {====================================================== |
122 ** {====================================================== |
123 ** Generic Buffer manipulation |
123 ** Generic Buffer manipulation |
124 ** ======================================================= |
124 ** ======================================================= |
125 */ |
125 */ |
126 |
126 |
127 |
127 |
128 |
128 |
129 typedef struct luaL_Buffer { |
129 typedef struct luaL_Buffer { |
130 char *p; /* current position in buffer */ |
130 char *p; /* current position in buffer */ |
131 int lvl; /* number of strings in the stack (level) */ |
131 int lvl; /* number of strings in the stack (level) */ |
132 lua_State *L; |
132 lua_State *L; |
133 char buffer[LUAL_BUFFERSIZE]; |
133 char buffer[LUAL_BUFFERSIZE]; |
134 } luaL_Buffer; |
134 } luaL_Buffer; |
135 |
135 |
136 #define luaL_addchar(B,c) \ |
136 #define luaL_addchar(B,c) \ |
137 ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ |
137 ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ |
138 (*(B)->p++ = (char)(c))) |
138 (*(B)->p++ = (char)(c))) |
139 |
139 |
140 /* compatibility only */ |
140 /* compatibility only */ |
141 #define luaL_putchar(B,c) luaL_addchar(B,c) |
141 #define luaL_putchar(B,c) luaL_addchar(B,c) |
142 |
142 |
143 #define luaL_addsize(B,n) ((B)->p += (n)) |
143 #define luaL_addsize(B,n) ((B)->p += (n)) |
144 |
144 |
145 LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); |
145 LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); |
146 LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); |
146 LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); |
147 LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); |
147 LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); |
148 LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); |
148 LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); |