new function 'lua_setallocf'

This commit is contained in:
Roberto Ierusalimschy 2005-09-20 14:55:10 -03:00
parent bf96d3fdd9
commit d8f1cca16e
3 changed files with 18 additions and 4 deletions

16
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.48 2005/09/01 17:42:22 roberto Exp roberto $
** $Id: lapi.c,v 2.49 2005/09/14 17:44:48 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -992,8 +992,20 @@ LUA_API void lua_concat (lua_State *L, int n) {
LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
lua_Alloc f;
lua_lock(L);
if (ud) *ud = G(L)->ud;
return G(L)->frealloc;
f = G(L)->frealloc;
lua_unlock(L);
return f;
}
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
lua_lock(L);
G(L)->ud = ud;
G(L)->frealloc = f;
lua_unlock(L);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.30 2005/08/26 17:36:32 roberto Exp roberto $
** $Id: ltests.c,v 2.31 2005/09/14 17:48:57 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -1124,6 +1124,7 @@ int luaB_opentests (lua_State *L) {
void *ud;
lua_assert(lua_getallocf(L, &ud) == debug_realloc);
lua_assert(ud == cast(void *, &memcontrol));
lua_setallocf(L, lua_getallocf(L, NULL), ud);
lua_state = L; /* keep first state to be opened */
luaL_register(L, "T", tests_funcs);
return 0;

3
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.211 2005/08/12 13:34:15 roberto Exp roberto $
** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -239,6 +239,7 @@ LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);