00001
00002
00003
00004
00005
00006
00007 #ifndef lmem_h
00008 #define lmem_h
00009
00010
00011 #include <stddef.h>
00012
00013 #include "llimits.h"
00014 #include "lua.h"
00015
00016 #define MEMERRMSG "not enough memory"
00017
00018
00019
00020 void *luaM_realloc ( lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size)
00021 ;
00022
00023
00024 void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
00025 int limit, const char *errormsg)
00026 ;
00027
00028 #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
00029 #define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0)
00030 #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
00031 cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
00032
00033 #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
00034 #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
00035 #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
00036 cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
00037
00038 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
00039 if (((nelems)+1) > (size)) \
00040 ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
00041
00042 #define luaM_reallocvector(L, v,oldn,n,t) \
00043 ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
00044 cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
00045
00046
00047 #endif
00048