aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-20 14:55:10 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-20 14:55:10 -0300
commitd8f1cca16ea9a682127bb328c8bdfbfb4ded3412 (patch)
treea43ca86e36a0d27ccda6c4599988cc2c69b50e34
parentbf96d3fdd9ee477faa774734453c27535a36b16f (diff)
downloadlua-d8f1cca16ea9a682127bb328c8bdfbfb4ded3412.tar.gz
lua-d8f1cca16ea9a682127bb328c8bdfbfb4ded3412.tar.bz2
lua-d8f1cca16ea9a682127bb328c8bdfbfb4ded3412.zip
new function 'lua_setallocf'
-rw-r--r--lapi.c16
-rw-r--r--ltests.c3
-rw-r--r--lua.h3
3 files changed, 18 insertions, 4 deletions
diff --git a/lapi.c b/lapi.c
index 65711ca0..16f469da 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.48 2005/09/01 17:42:22 roberto Exp roberto $ 2** $Id: lapi.c,v 2.49 2005/09/14 17:44:48 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -992,8 +992,20 @@ LUA_API void lua_concat (lua_State *L, int n) {
992 992
993 993
994LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { 994LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
995 lua_Alloc f;
996 lua_lock(L);
995 if (ud) *ud = G(L)->ud; 997 if (ud) *ud = G(L)->ud;
996 return G(L)->frealloc; 998 f = G(L)->frealloc;
999 lua_unlock(L);
1000 return f;
1001}
1002
1003
1004LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
1005 lua_lock(L);
1006 G(L)->ud = ud;
1007 G(L)->frealloc = f;
1008 lua_unlock(L);
997} 1009}
998 1010
999 1011
diff --git a/ltests.c b/ltests.c
index 7530b7f9..70a66ce0 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.30 2005/08/26 17:36:32 roberto Exp roberto $ 2** $Id: ltests.c,v 2.31 2005/09/14 17:48:57 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1124,6 +1124,7 @@ int luaB_opentests (lua_State *L) {
1124 void *ud; 1124 void *ud;
1125 lua_assert(lua_getallocf(L, &ud) == debug_realloc); 1125 lua_assert(lua_getallocf(L, &ud) == debug_realloc);
1126 lua_assert(ud == cast(void *, &memcontrol)); 1126 lua_assert(ud == cast(void *, &memcontrol));
1127 lua_setallocf(L, lua_getallocf(L, NULL), ud);
1127 lua_state = L; /* keep first state to be opened */ 1128 lua_state = L; /* keep first state to be opened */
1128 luaL_register(L, "T", tests_funcs); 1129 luaL_register(L, "T", tests_funcs);
1129 return 0; 1130 return 0;
diff --git a/lua.h b/lua.h
index aa969ae0..0bd97084 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.211 2005/08/12 13:34:15 roberto Exp roberto $ 2** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -239,6 +239,7 @@ LUA_API int (lua_next) (lua_State *L, int idx);
239LUA_API void (lua_concat) (lua_State *L, int n); 239LUA_API void (lua_concat) (lua_State *L, int n);
240 240
241LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 241LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
242LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
242 243
243 244
244 245