misc/liblua/lauxlib.h
changeset 10017 de822cd3df3a
parent 2812 0a24853de796
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    22 #define luaL_getn(L,i)          ((int)lua_objlen(L, i))
    22 #define luaL_getn(L,i)          ((int)lua_objlen(L, i))
    23 #define luaL_setn(L,i,j)        ((void)0)  /* no op! */
    23 #define luaL_setn(L,i,j)        ((void)0)  /* no op! */
    24 #endif
    24 #endif
    25 
    25 
    26 #if defined(LUA_COMPAT_OPENLIB)
    26 #if defined(LUA_COMPAT_OPENLIB)
    27 #define luaI_openlib	luaL_openlib
    27 #define luaI_openlib    luaL_openlib
    28 #endif
    28 #endif
    29 
    29 
    30 
    30 
    31 /* extra error code for `luaL_load' */
    31 /* extra error code for `luaL_load' */
    32 #define LUA_ERRFILE     (LUA_ERRERR+1)
    32 #define LUA_ERRFILE     (LUA_ERRERR+1)
    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);
   165 #define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))
   165 #define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))
   166 
   166 
   167 #define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
   167 #define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
   168 
   168 
   169 
   169 
   170 #define luaL_reg	luaL_Reg
   170 #define luaL_reg    luaL_Reg
   171 
   171 
   172 #endif
   172 #endif
   173 
   173 
   174 
   174