00001
00002
00003
00004
00005
00006
00007
00008 #ifndef lauxlib_h
00009 #define lauxlib_h
00010
00011
00012 #include <stddef.h>
00013 #include <stdio.h>
00014
00015 #include "lua.h"
00016
00017
00018
00019
00020 #define LUA_ERRFILE (LUA_ERRERR+1)
00021
00022
00023 typedef struct luaL_Reg {
00024 const char *name;
00025 lua_CFunction func;
00026 } luaL_Reg;
00027
00028
00029 LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
00030 #define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
00031
00032 LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
00033 LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
00034 LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
00035 LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
00036 LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
00037 LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
00038 size_t *l);
00039 LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
00040 const char *def, size_t *l);
00041 LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
00042 LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
00043
00044 LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
00045 LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
00046 lua_Integer def);
00047 LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
00048 LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
00049 lua_Unsigned def);
00050
00051 LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
00052 LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
00053 LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
00054
00055 LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
00056 LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
00057 LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
00058 LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
00059
00060 LUALIB_API void (luaL_where) (lua_State *L, int lvl);
00061 LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
00062
00063 LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
00064 const char *const lst[]);
00065
00066 LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
00067 LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
00068
00069
00070 #define LUA_NOREF (-2)
00071 #define LUA_REFNIL (-1)
00072
00073 LUALIB_API int (luaL_ref) (lua_State *L, int t);
00074 LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
00075
00076 LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
00077 const char *mode);
00078
00079 #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
00080
00081 LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
00082 const char *name, const char *mode);
00083 LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
00084
00085 LUALIB_API lua_State *(luaL_newstate) (void);
00086
00087 LUALIB_API int (luaL_len) (lua_State *L, int idx);
00088
00089 LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
00090 const char *r);
00091
00092 LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
00093
00094 LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
00095
00096 LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
00097 const char *msg, int level);
00098
00099 LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
00100 lua_CFunction openf, int glb);
00101
00102
00103
00104
00105
00106
00107
00108
00109 #define luaL_newlibtable(L,l) \
00110 lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
00111
00112 #define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
00113
00114 #define luaL_argcheck(L, cond,numarg,extramsg) \
00115 ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
00116 #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
00117 #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
00118 #define luaL_checkint(L,n) (static_cast<int>(luaL_checkinteger(L, (n))))
00119 #define luaL_optint(L,n,d) (static_cast<int>(luaL_optinteger(L, (n), (d))))
00120 #define luaL_checklong(L,n) (static_cast<long>(luaL_checkinteger(L, (n))))
00121 #define luaL_optlong(L,n,d) (static_cast<long>(luaL_optinteger(L, (n), (d))))
00122
00123 #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
00124
00125 #define luaL_dofile(L, fn) \
00126 (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
00127
00128 #define luaL_dostring(L, s) \
00129 (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
00130
00131 #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
00132
00133 #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
00134
00135 #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
00136
00137
00138
00139
00140
00141
00142
00143
00144 typedef struct luaL_Buffer {
00145 char *b;
00146 size_t size;
00147 size_t n;
00148 lua_State *L;
00149 char initb[LUAL_BUFFERSIZE];
00150 } luaL_Buffer;
00151
00152
00153 #define luaL_addchar(B,c) \
00154 ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
00155 ((B)->b[(B)->n++] = (c)))
00156
00157 #define luaL_addsize(B,s) ((B)->n += (s))
00158
00159 LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
00160 LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
00161 LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
00162 LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
00163 LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
00164 LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
00165 LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
00166 LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
00167
00168 #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 #define LUA_FILEHANDLE "FILE*"
00187
00188
00189 typedef struct luaL_Stream {
00190 FILE *f;
00191 lua_CFunction closef;
00192 } luaL_Stream;
00193
00194
00195
00196
00197
00198
00199 #if defined(LUA_COMPAT_MODULE)
00200
00201 LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
00202 int sizehint);
00203 LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
00204 const luaL_Reg *l, int nup);
00205
00206 #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
00207
00208 #endif
00209
00210
00211 #endif
00212
00213